Hi, I've been programming in Java for 2 years and C/C++ for almost a year now. I'm still confused at some things because the difference of the languages.
I'd like to know how to initialize an array that's set as a data member of a class in the constructor.
Here's the code in Java :
public class ExpandableArray {
int Array[];
public final int m = 2;
public ExpandableArray(int number){
Array = new int[m*number];
}
}
how do I translate it to C++? I don't really know how you'd initialize the array in C++, because with Java, I use the "new" command.
Thanks for any help you can give me :)
class ExpandableArray {
private:
int* Array; //Note the use of pointer here
/*Other private fields here*/
public:
intconst /*<- instead of final*/ m = 2; //I do not know why do you need it, so I will leave it
ExpandableArray(int number) //I will combine declaration with definition here for simlicity
{
Array = newint[m*number];
}
}