Thread: time needed destructor~

  1. #1
    flashing vampire black's Avatar
    Join Date
    May 2002
    Posts
    563

    time needed destructor~

    Hi guys I read something about destructor and I wonder if it is only needed when pointer member existed in certain member ? it seemed useless to delete something like int or char when our class instances are gone.

    thanx in advance~
    Never end on learning~

  2. #2
    Registered User nag's Avatar
    Join Date
    May 2002
    Posts
    22
    it is mostly used when you have allocated dynamic memory,because if you allocate dynamic memory it will not be deleted automatically even class instances are destroyed(out of scope).
    you have to explicitly delete that memoery in a destructor....
    Two men looked out from Prison Bars,One saw the mud,the other saw stars.

  3. #3
    Registered User
    Join Date
    Jan 2003
    Posts
    311
    Classes with virtual functions should also have a virtual destructor, even if it does nothing.(faq) Also remember the rule of three if you need to write your own dtor, copy ctor, or assignment operator, you generally need to write all three.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. How to get current time
    By tsubasa in forum C Programming
    Replies: 3
    Last Post: 05-01-2009, 02:03 AM
  2. Execution Time - Rijandael encryption
    By gamer4life687 in forum C++ Programming
    Replies: 5
    Last Post: 09-20-2008, 09:25 PM
  3. Journey time prog 1 minute wrong
    By mike_g in forum C Programming
    Replies: 4
    Last Post: 10-12-2006, 03:41 AM
  4. The new FAQ
    By Hammer in forum A Brief History of Cprogramming.com
    Replies: 34
    Last Post: 08-30-2006, 10:05 AM
  5. calculating user time and time elapsed
    By Neildadon in forum C++ Programming
    Replies: 0
    Last Post: 02-10-2003, 06:00 PM