I just do not get something about about a dynamic array with a container class here is an example of how I do it.
A container class:
class Container{
private:
int n, current;
Class *C;
public:
Container(): C(NULL), n(0), current(0){}
void expandC(int ammount){
Class *NewClass= new Class[ammount];
for (int i = 0; i < n; i++)
NewClass[i] = C[i];
delete []C;
C = NewClass;
n = ammount;
}
};
Why do I get an error on a delete[] C
line?
EDIT: If caught the essence of the rule of three it means that you have to define a copy constructor an assignment operator or a destructor. In my case the most important is probably the copy constructor.
Here is a how I understood how they should be defined in my case:
Container(): C(NULL), n(0), current(0){}
Container(int N, vector<string> a){
C = new Class[N];
for(int i = 0; i<n; i++){C->setA(a[i]);}
n=N;
}
~Container(){ delete [] C;}
It is a good practice and I am going to use it i future but I in this case it have not helped me.
I have noted in the comments that my error is related with access violation by I am posting it here just in case.
Unhandled exception at 0x53f0edfc (msvcr90d.dll) in dinamicTest.exe: 0xC0000005: Access violation writing location 0xabababab.
Here is the requested initial full version of this program http://pastebin.com/djTz36Tu