Which is the right way to allocate memory via new
in the C++ constructor. First way in the argument list:
class Boda {
int *memory;
public:
Boda(int length) : memory(new int [length]) {}
~Boda() { delete [] memory; }
};
or in the body of constructor:
class Boda {
int *memory;
public:
Boda(int length) {
memory = new int [length];
}
~Boda() { delete [] memory; }
};
Thanks, Boda Cydo.