What is the right way to allocate memory in the C++ constructor?
问题 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. 回答1: I think the simplest way to do this would be to use a boost scoped array and let someone else's well tested