Confused with destructors
C / C++ / MFC
3
Posts
2
Posters
0
Views
1
Watching
-
I have:
typedef std::basic_string String;
The i usevoid whatever() { String myString = "anton"; }
The question is, would my string be destroyed, or i had just eatent a memory leak. -
I have:
typedef std::basic_string String;
The i usevoid whatever() { String myString = "anton"; }
The question is, would my string be destroyed, or i had just eatent a memory leak. -
Your string will be destroyed correctly once the function ends, as the variable is local to the function. If you had done:
void whatever() { String *myString = new String ("anton"); }
Then you would have had a leakThx.