I had a question on why my pointer ptr is having a core dumped error when its deleted.I'm currently testing the classes on GoogleTest.
I would not usually use multiple inheritance, but this class hierarchy was dictated by a class assignment.
For class E, the reason I called the constructor for C, was that if I left out it out, it would automatically resort to the default constructor of C, which is not what I want (Why is Default constructor called in virtual inheritance?). In my actual program, all the constructors have parameters, but I have left them out for simplicity. The simplified code below still throws the exact same error.
class A{
public:
virtual ~A(){}
};
class B: virtual public A{
public:
virtual ~B(){}
};
class C: virtual public B{
public:
virtual ~C(){}
};
class M: virtual public A{
public:
virtual ~M(){}
};
class D: virtual public C{
public:
D():C(){// calls constructor of class C
}
virtual ~D(){}
};
class E: virtual public M, virtual public D{
public:
E():M(),C(),D(){//calls constructors of class M, C, and D
}
~E(){}
}
Within GoogleTest, if I run
TEST(filename,testE){
A * ptr = new E();
delete ptr; // free(): invalid pointer, Aborted (core dumped)
}
Thank you.