Hey peeps,
I have a couple of (fairly simple) C++ questions I'd like answered, if you'd be so kind:
1. If I have a method within a class that creates a pointer to an object using the new keyword, can it return a pointer to that object or is it lost on procedure exit?
For example:
Code:
// Incomplete code...
SDL_Surface *temp;
SDL_Surface* getFrame(){
temp = SDL_CreateRGBSurface(...etc....);
return temp;
}
Is that valid or is temp lost?
2. Does EVERYTHING I create using
new need a corresponding
delete statement? Until recently I believed that it was only things of indeterminate size (for example created using malloc) that needed freeing or deleting, but looking around it seems this is not the case, and now in every class's destructor I have several delete statements to cater for the numerous objects created within the class. Is this right?
That's all folks! I'm not new to programming, I've been a Java programmer for years, but C++ is throwing up some interesting new challenges for me.
Thanks!
Kk