Hello,
I've been coding a class for which there is a dynamic array member, in the constructor I wrote :
...
Blah = new Whatever[numberOfElements];
...
in the destructor of course I have to delete this array, or there will be a memory leake, so, I wrote in the destructor:
....
delete [] Blah ;
....
every thing works fine, until I call a static member function, for which the parametters are of this class, after the call of the function, the array blah does not exist where I called the member function, the code looks like this:
....
MyClass x1;
MyClass::StaticFunction(x1);
....
after the static function returns, the member array Blah is deleted, here what happens, when I call the fumction, the parametter is copied and passed to the function yClass::StaticFunction(x1), a typical pass by value, at the end of this function, the copy of object x1 is deleted, with all of its members, the Blah array Blah member is dhared with x1 in the caller function, so it is deleted as well, I want to prevent this from hapenning, yet, I don't want leaks to happen, can nayone help Please? I would be greatly appreciated.
I've been coding a class for which there is a dynamic array member, in the constructor I wrote :
...
Blah = new Whatever[numberOfElements];
...
in the destructor of course I have to delete this array, or there will be a memory leake, so, I wrote in the destructor:
....
delete [] Blah ;
....
every thing works fine, until I call a static member function, for which the parametters are of this class, after the call of the function, the array blah does not exist where I called the member function, the code looks like this:
....
MyClass x1;
MyClass::StaticFunction(x1);
....
after the static function returns, the member array Blah is deleted, here what happens, when I call the fumction, the parametter is copied and passed to the function yClass::StaticFunction(x1), a typical pass by value, at the end of this function, the copy of object x1 is deleted, with all of its members, the Blah array Blah member is dhared with x1 in the caller function, so it is deleted as well, I want to prevent this from hapenning, yet, I don't want leaks to happen, can nayone help Please? I would be greatly appreciated.