jeudi 13 août 2015

c++ double free or corruption error in destructor of a class derived from multiple classes

I am trying to write a multiple step abstract class like Plant is the top abstract class, Tree & Fruit are abstract classes derived from it. Oak is a normal class derived from Tree, Strawberry is also normal class derived from Fruit and Apple is a normal class derived from both Tree and Fruit.

While testing them with a simple main, I get this error. Here is my main.cpp:

int main(int argc, char const *argv[])
{
    long c = 500000;
    float d = 27.8;
    long e = 3000;

    Apple apple1("applecuk", 1, 39, 400, 0, 2, 3, c, d, e);
    apple1.bilgi();
    cout << "-------------------------------------------------" << endl;
    apple1.eat();
    apple1.info();
    apple1.cut();

    cout << "-------------------------------------------------" << endl;

    Oak oak1("oakcan", 1, 5, 1000, 2);
    oak1.info();
    oak1.cut();

    cout << "-------------------------------------------------" << endl;

    long a = 100000;
    float b = 14.3;
    Strawberry strw1("strwcik", 3, 2, 3, a, b);
    strw1.info();
    strw1.eat();

    cout << "-------------------------------------------------" << endl;

return 0;
}

At first everything is ok. Then, after the last ------ part, the program is starting to destruct the objects from last one (strawberry) to the first one (apple). But after strawberry, Fruit and Plant; it gives this error.

I think the next destructor is can't be called because, it is already destroyed. But I am not sure. How can I fix that?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire