I am at the point learning classes/destructors in c++ and the need to return a pointer from a class member:
size_t * classname :: function();
but it doesn't work.
My logic is to declare a class variable e.g. classname * p_p = classfunction(data);
that should access the class member:
size_t * classname :: classfunction(data)
{
... do something ... new p_p;
return p_p;
}
So the pointer address in theory gets returned to the main() variable p_p each time the member function of the class gets called. Or should but doesn't and the program crashes somehow but not even sure on which point.
There is no compiler warning or error and the debugger doesn't stops anywhere and I find nothing on returning a pointer from a class member function at all nor that it isn't allowed or something.
Also if there IS a syntax to return a pointer from a class member function I would need to have a syntax for delete the "new p_p
".
So my question is: Should it work and how would I get this running or why is that maybe not working or pot. forbidden? In my logic it should be a proper way but I doubt I will be wrong somehow and classes doesn't support functions completely.
Aucun commentaire:
Enregistrer un commentaire