Need some help with Delete

This is a discussion on Need some help with Delete within the C++ Programming forums, part of the General Programming Boards category; A quick question... How do you delete a dynamically created array composed of base class pointers, where each pointer is ...

  1. #1
    Registered User
    Join Date
    Nov 2001
    Posts
    16

    Question Need some help with Delete

    A quick question...

    How do you delete a dynamically created array composed of base class pointers, where each pointer is pointing to objects of the base class and various derived classes?

    Thanks in advance

  2. #2
    Skunkmeister Stoned_Coder's Avatar
    Join Date
    Aug 2001
    Posts
    2,572
    As long as you have already deleted the pointed to objects or you have another copy of the pointers then all you need do is....

    delete[] pointer_to_dynamic_array;
    Free the weed!! Class B to class C is not good enough!!
    And the FAQ is here :- http://faq.cprogramming.com/cgi-bin/smartfaq.cgi

  3. #3
    Skunkmeister Stoned_Coder's Avatar
    Join Date
    Aug 2001
    Posts
    2,572
    afterthought....

    If you want to know how to delete the objects pointed to first then as long as your base class has a virtual destructor then you can call delete on the base class pointers knowing that the derived class destructor will be called.
    Free the weed!! Class B to class C is not good enough!!
    And the FAQ is here :- http://faq.cprogramming.com/cgi-bin/smartfaq.cgi

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Proper Usage of the delete Operator
    By thetinman in forum C++ Programming
    Replies: 7
    Last Post: 04-26-2007, 12:53 AM
  2. BST delete again, but this time I think I'm close
    By tms43 in forum C++ Programming
    Replies: 9
    Last Post: 11-05-2006, 06:24 PM
  3. delete and delete []
    By Lionel in forum C++ Programming
    Replies: 8
    Last Post: 05-19-2005, 02:52 PM
  4. why is this prog crashing on delete?
    By Waldo2k2 in forum Windows Programming
    Replies: 2
    Last Post: 12-04-2002, 11:17 PM
  5. Problem need help
    By Srpurdy in forum C++ Programming
    Replies: 1
    Last Post: 07-24-2002, 01:45 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21