I have some problems with applying polymorphism in this example. This question is similar to my last question.
C ++, virtual inheritance, strange problem of abstract class + clone
There are 3 abstract classes:
class A { public: virtual A * copy () const = 0; virtual ~A() = 0; }; A::~A(){} class B { public: virtual B * copy () const = 0; virtual ~B() = 0; }; B::~B(){} class C: virtual public A , public B { public: virtual C * copy () const = 0; virtual ~C() = 0; }; C::~C(){}
and two inherited classes using virtual inheritance
class D: virtual public A { public: virtual D * copy () const {return new D (*this);} virtual ~D() {} }; class E: virtual public D , public C { public: virtual E * copy () const {return new E (*this);} virtual ~E() {} };
The above error only occurs using the MSVS 2010 compiler, g ++ compiles this code in order.
Class Diagram (Simplified)
.......... A .... B..... ........../.\..../...... ........./...\../....... ......../.....\/........ .......D...... C........ ........\...../......... .........\.../.......... ..........\./........... ...........E............
The last discussion closes with the result: remove the declaration of the copy () method from class C.
class C: virtual public A , public B { public:
My sample code using polymorphism should create a vector of pointers to C. After deleting an element, I want to create a copy of it ... I need a copy () declaration in class C, so deleting the declaration is not enough and this does not solve the problem.
int main(int argc, char* argv[]) { std::vector <C*> items; items.push_back(new E()); items.push_back(new E()); items[0]->copy(); return 0; }
Could you please help me, please, how to fix the code for translation on VS 2010?