Deleting pointers to virtual functions

This is a discussion on Deleting pointers to virtual functions within the Windows Programming forums, part of the Platform Specific Boards category; Gidday, I'm using CBuilder 6 and I have a class that looks something like this: Code: class SHIP { public: ...

  1. #1
    stovellp
    Guest

    Deleting pointers to virtual functions

    Gidday,

    I'm using CBuilder 6 and I have a class that looks something like this:

    Code:
    class SHIP
    {
    public:
         virtual AnsiString GetName();
    };
    I then have classes (Eg: CRUISESHIP, CARGOSHIP) that inherit this and overwrite GetName().

    I have then created an array of SHIP's (SHIP * Ships[10]), and when the user creates a new CRUISESHIP or CARGOSHIP it is placed into this array.

    This allows me to write:
    Code:
    CRUISESHIP * Temp = new CRUISESHIP;
    /* Do some other stuff */
    Ships[0] = Temp;
    And there are no problems. The problem is, when I try to delete any of the Ships[], I get an error saying Assert failed and some other stuff.

  2. #2
    Skunkmeister Stoned_Coder's Avatar
    Join Date
    Aug 2001
    Posts
    2,572
    are your destructors virtual? You do have virtual destructors dont you?
    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. Conversion of pointers to functions
    By hzmonte in forum C Programming
    Replies: 0
    Last Post: 01-20-2009, 01:56 AM
  2. Pointers to Class Member Functions
    By Dark_Phoenix in forum C++ Programming
    Replies: 6
    Last Post: 09-02-2007, 03:21 PM
  3. virtual functions
    By BKurosawa in forum C++ Programming
    Replies: 9
    Last Post: 08-12-2007, 03:12 AM
  4. Virtual Functions
    By guda in forum C++ Programming
    Replies: 3
    Last Post: 11-16-2004, 04:13 PM
  5. Exporting Object Hierarchies from a DLL
    By andy668 in forum C++ Programming
    Replies: 0
    Last Post: 10-20-2001, 02:26 PM

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