PDA

View Full Version : c++ anonymous classes?


BillGatesJR
05-23-2010, 10:50 PM
This may seem like a dumb question, but anywho:

In C++ I am building a GUI, and I have already defined the window class. I'm placing all of the controls on the window (which are really just classes themselves) in the default constructor.

I know that normally when you need a new instance of a class at run time you would say something like:

Class myClass = new Class;

I already did this for all of the textboxes on the window, now I am making the labels to go next to the textboxes. I won't need to access the labels after putting them on the window, so is it really necessary to create a pointer variable? Couldn't I just say:

new Label;

Will this "anonymous" object automatically be deleted when the class itself is deleted (or goes out of scope?), or do I need to add a pointer and call delete in the destructor to avoid memory leak?

Please bear with me as I'm still getting used to the whole object-oriented approach, since I come from more of a scripting background.