How the object is dead?

  After an object is constructed, the system is constructed out after the structure and whether or not the compiler? 

  Today review of the C + + language, for a small procedure.    Found a constructed object, the system will be in the VC6 Below call themselves such Analysis of the structure cold and heat, and in Dev-C + + (using gcc) Below will not call?    Besides, if the object is to establish the guidelines, then the system will not call out its own structure function. 

  Code as follows: 

  # Include 

  Using namespace std; 

  Class Counter 
  ( 

  Private: 
  Int elem; 
  Public: 
  Counter (); 
  Counter (int elem); 
  ~ Counter (); 
  ); 

  Static int counter; 

  Counter:: Counter () 
  ( 
  Elem = 0; 
  Counter + +; 
  Cout << "in Counter ()" <    <Endl; 
  Cout << "counter =" <<endl; 
  ) 

  Counter:: Counter (int arg) 
  ( 
  Elem = arg; 
  Counter + +; 
  Cout << "in Counter (int)" <<endl 
  Cout << "counter =" <<endl; 
  ) 

  Counter:: ~ Counter () 
  ( 
  Counter -; 
  Cout << "in ~ Counter ()"<< endl; 
  Cout << "counter =" <<endl; 
  ) 

  Int main (int argc, char * argv []) 
  ( 
  Counter c1; 
  Counter c2; 
  Counter c3; 
  Counter * cp = new Counter (10); 
  Cp-> ~ Counter (); 

  Return 0; 
  ) 

  VC6 in the operating results are: 

  In Counter () 
  Counter = 1 
  In Counter () 
  Counter = 2 
  In Counter () 
  Counter = 3 
  In Counter (int) 
  Counter = 4 
  In-Counter () 
  Counter = 3 
  In-Counter () 
  Counter = 2 
  In-Counter () 
  Counter = 1 
  In-Counter () 
  Counter = 0 
  Press any key to continue 

  In Dev-C + + types of results: 

  In Counter () 
  Counter = 1 
  In Counter () 
  Counter = 2 
  In Counter () 
  Counter = 3 
  In Counter (int) 
  Counter = 4 
  In-Counter () 
  Counter = 3 
  Press any key to continue.. 

=================================

  Conclusion: 

  The destruction of objects in the stage, calling out whether the structure function at the compiler, rather than the language definition.    Therefore, the actual programming, this is the object of the control of the life cycle is very practical.  :-)

Bookmark it: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • Digg
  • Sphinn
  • del.icio.us
  • Google
  • DotNetKicks
  • DZone
  • Furl
  • Netvouz

Tags:

Releated Articles


0 Comments to “How the object is dead?”

No Comments. Send your comment.

Leave a Reply

You must be logged in to post a comment.