Hi everyone,
I'm sure I'm doing something silly here!
Basically my constructor creates a pointer initialised to null, then in one of my functions I create an integer array on the heap using the new keyword.
Now basically I have a data structure that needs to be copied, like so
mydatastructure structuretwo = structureone;
Now in my copy constructor I have got the basics...
mydatastructure::mydatastructure(const mydatastructure& copystructure)
{
_numberData = new int [1000]; //Create a new array on the heap
_numberData = copystructure._numberData;
}
Hope that makes sense as I've cut out most of the code. Now I know that I'm creating a new array the size of 1000 on the heap, but instead of the previous data structure been copied into the new one, the pointer ends up pointing to the memory location of the old datastructure instead.. where as I need it to be pointing at the new location and the old data to be copied to the new location too.
Can anybody help? I feel so close to the solution but I just can't get there!
Many Thanks :-)