Jump to content
  • Advertisement
Sign in to follow this  
ricekrispyw

Destructor problems

This topic is 4839 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm having problems with virtual constructors, which I implemented in my base classes to solve the memory issue that occurs with non-virtual base class destructors. (If you don't know about it, go here to learn.) Here's how it's set up (using example classes):
class Vehicle
{
public:
    Vehicle() {...}
    virtual ~Vehicle {...}
    ...
};

class Car
{
public:
    Car() {...}
    ~Car() {}
    ...
};

class Truck
{
public:
    Truck() {...}
    ~Truck() {}
    ...
};


Note that the derived destructors are empty. I dunno if it matters. I then create a list (it's actually a map, but whatever) of Vehicle pointers. I then create cars and trucks and add them to the list. Then, come clean up time, I iterate through the list, deleting each entry in the list (remember, they're Vehicles). However, I get a runtime error that I made a pure-virtual function call. What did I do wrong? Thanks in advance.

Share this post


Link to post
Share on other sites
Advertisement
That can happen if you double delete a pointer, or you call a virtual function in a destructor if the function is pure virtual in the class that the call is declared in. Ex:

class Vehicle {
public:
~Vehicle() {
fuzzy();
}
virtual void fuzzy(void) = 0;
};

Share this post


Link to post
Share on other sites
I must be double-deleting, but I checked on that. I'll double-double check.

[EDIT]
I was calling a pure-virtual function, but I didn't realize it. All of NovodeX's stuff ius pure virtual. Thanks.

[Edited by - ricekrispyw on August 17, 2005 1:51:46 PM]

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!