I am not sure if this is the right forum of this question, but I will try here s
ID: 659012 • Letter: I
Question
I am not sure if this is the right forum of this question, but I will try here since this question about the c++ language. The problem:
I use one global variable in my code which is a graphics object. The thing is that when I shut down the program I tried to delete all the created objects (in a function called close, since I wanted to finish some processes from an C API as well). However, when I deleted that global graphics object I got a memory access violation error at the end of main. The reason for this was that the destructor was called again when main ended. This was something that I was not aware of. This led me to the for this program completely irrelevant (since I still wanted to keep the variable until the GUI closed), but for c++ programming really relevant question; Is it impossible to destroy a global c++ object before the end of main?
However, I read this
Static: Objects declared in global or namespace scope (
Explanation / Answer
However, though versions of this text appear all over on the internet my question is not completely answered by this explanation. Though it may be implied, since global variables always seem to be static it would be nice to have a straight out answer.
If you didn't explicitly create it, you don't need to explicitly destroy it. Let's just remove some of the words from your standard quote:
Static: Objects declared in global or namespace scope (
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.