Click here to Skip to main content
15,921,941 members
Home / Discussions / ATL / WTL / STL
   

ATL / WTL / STL

 
GeneralRe: Controlling the MediaPlayer ocx control Pin
Michael Dunn22-Oct-03 12:48
sitebuilderMichael Dunn22-Oct-03 12:48 
GeneralRe: Controlling the MediaPlayer ocx control Pin
bryces22-Oct-03 17:16
bryces22-Oct-03 17:16 
GeneralRe: Controlling the MediaPlayer ocx control Pin
Michael Dunn22-Oct-03 20:29
sitebuilderMichael Dunn22-Oct-03 20:29 
GeneralRe: Controlling the MediaPlayer ocx control Pin
rbeckett16-Nov-03 14:40
rbeckett16-Nov-03 14:40 
GeneralCollections and containers. Pin
WREY20-Oct-03 5:30
WREY20-Oct-03 5:30 
GeneralRe: Collections and containers. Pin
ZoogieZork20-Oct-03 5:44
ZoogieZork20-Oct-03 5:44 
GeneralRe: Collections and containers. Pin
WREY20-Oct-03 6:07
WREY20-Oct-03 6:07 
GeneralRe: Collections and containers. Pin
ZoogieZork20-Oct-03 7:01
ZoogieZork20-Oct-03 7:01 
WREY wrote:
When is the destructor for the container called? Is it an automatic thing, or would you have to purposely call it (other than when it's done automatically for you upon exiting the program)?

The destructor for any type in C++ is called (implicitly):

  • For stack-allocated objects, it's called when the object goes out of scope.
  • For heap-allocated objects, it's called when you use delete on it.


So, for example:

void foo() {
  std::vector<MyClass> myvec;
  myvec.push_back(MyClass());
  myvec.push_back(MyClass());
  myvec.push_back(MyClass());
} // myvec and all elements are destroyed here.
myvec is destroyed at the end of the function since it is allocated on the stack. Each of its elements is also destroyed since they are not pointers. (Also I should note that when adding items to an STL container, the items are always added by copying, so each of those calls to push_back() is actually creating a new instance of MyClass, adding a copy of that instance, then destroying the original instance).

A couple more examples to illustrate the point:

void foo() {
  std::vector<MyClass*> myvec;
  myvec.push_back(new MyClass());
  myvec.push_back(new MyClass());
  myvec.push_back(new MyClass());
} // myvec is destroyed, but the instances of
  // MyClass persist on the heap.
void foo() {
  std::vector<MyClass> *myvec =
    new std::vector<MyClass>();
  myvec->push_back(MyClass());
  myvec->push_back(MyClass());
  myvec->push_back(MyClass());
} // myvec and the elements persist on the heap.
WREY wrote:
Both the vector and the map containers are defined in the same class, and instantiated in the same function. However, they were populated in different functions, but when they met back up together, the "size()" of the map showed zero (even though the class object in which they reside was still alive and no "erase()" function was used).

I'd have to see the code, or at least a minimal test case that illustrates the problem.

- Mike
GeneralRe: Collections and containers. Pin
WREY20-Oct-03 7:52
WREY20-Oct-03 7:52 
General&quot;-Embedding&quot; in the SCM - Atl Servers/Services Pin
IanF20-Oct-03 3:48
IanF20-Oct-03 3:48 
GeneralContainer &amp; Dll Pin
Bernhard20-Oct-03 3:13
Bernhard20-Oct-03 3:13 
GeneralRe: Container &amp; Dll Pin
geo_m21-Oct-03 1:50
geo_m21-Oct-03 1:50 
GeneralRe: Container &amp; Dll Pin
Bernhard21-Oct-03 19:16
Bernhard21-Oct-03 19:16 
GeneralCAccessor question Pin
Paul Silvernail20-Oct-03 0:31
Paul Silvernail20-Oct-03 0:31 
GeneralAny questions Pin
El'Cachubrey19-Oct-03 23:14
El'Cachubrey19-Oct-03 23:14 
Generalinserting ActiveX control with WTL... (VS.NET2003) Pin
tlpr16-Oct-03 21:58
tlpr16-Oct-03 21:58 
GeneralRe: inserting ActiveX control with WTL... (VS.NET2003) Pin
rlodina30-Oct-03 3:06
rlodina30-Oct-03 3:06 
QuestionWhere have my connection point fired events gone? Pin
Colin F16-Oct-03 1:01
sussColin F16-Oct-03 1:01 
AnswerRe: Where have my connection point fired events gone? Pin
Michael P Butler19-Oct-03 23:29
Michael P Butler19-Oct-03 23:29 
GeneralRe: Where have my connection point fired events gone? Pin
Colin Foster20-Oct-03 23:16
Colin Foster20-Oct-03 23:16 
GeneralStatusbars in dialog based application Pin
tareqsiraj15-Oct-03 18:16
tareqsiraj15-Oct-03 18:16 
GeneralRe: Statusbars in dialog based application Pin
tareqsiraj17-Oct-03 2:56
tareqsiraj17-Oct-03 2:56 
GeneralRe: Statusbars in dialog based application Pin
rbeckett16-Nov-03 14:56
rbeckett16-Nov-03 14:56 
GeneralDirectory only dialog box Pin
Leo Smith15-Oct-03 16:32
Leo Smith15-Oct-03 16:32 
GeneralRe: Directory only dialog box Pin
tareqsiraj15-Oct-03 18:23
tareqsiraj15-Oct-03 18:23 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.