I'm a little bit confused on how to correctly allocate/deallocate dynamical array of objects. Here is my scenario:
class Tuple { public: Tuple(int columns); ~Tuple(); void set(int i, string d); string get(int i); int columnCount(); private: string *data; int columns; }; Tuple::Tuple(int columns) { this->columns = columns > 0 ? columns : 0; if (this->columns > 0) { data = new string[this->columns]; } else { data = 0; } } Tuple::~Tuple() { if (columns > 0) { delete data; } } Now, when I call the following code I get a segfault:
Tuple *t = new Tuple(4); //some code delete t; What is wrong with my denstructor?