Apr 2, 2011 at 8:31pm UTC
Hello,
I want to create an array of object of class MyClass, but with different parameters for the constructor. My best move is:
1 2 3 4
MyClass * my_array;
my_array = new MyClass[2];
my_array[0] = new MyClass(0);
my_array[1] = new MyClass(1);
There is no better way?!
MyClass have an operator []. But to call it, I must do:
Again, is there a better syntax?
Thank you.
Last edited on Apr 2, 2011 at 8:32pm UTC
Apr 2, 2011 at 9:28pm UTC
@Athar:
Thank you! I have a lot of reading with vectors, lists and deques. I'm sure I will find what I need.
@Wasabi:
My problem was the pointless call to the default constructor by my_array = new MyClass[2];
. Sorry for my imprecision and thank you anyway.