Thursday, 22 August 2013

Deleting a pointer to global variable?

Deleting a pointer to global variable?

So, i have two global variables, that i want to point to object of a
certain class. I have them declared in one .h file as
extern Obj* pointer.
I inicialize that variable inside my main function, as follows:
pointer = new Obj();
later on, i call some functions inside main etc. Can i call delete
operator at the end of main, like so:
delete pointer;
My main, in general would look like:
int main(){
pointer = new Obj();
...
delete pointer;
}

No comments:

Post a Comment