I am confused regarding the best way to handle a return variables from a method.
I have a class with one method that return a char* var
this var was created using the new keyword
this var was declared as a global variable in order to be deleted later on on the destructor method.
- Code: Select all
char * myfunc()
{
var= new char[len];
return var;
}
I know that I must call delete[] var in order to free memory correctly.
But where exactly should I do this?
at the destructor of the class ?
is what I am doing is correct?
Then how should I handle the return value correctly if i want to keep using it after the object is destroyed?
thanks.
