jeudi 2 juin 2016

C++, inherited copy ctors does not work?

Consider following code:

class TBase {
public:
   TBase();
   TBase(const TBase &);
};

class TDerived: public TBase {
public:
   using TBase::TBase;
};

void f() {
   TBase Base;
   TDerived Derived(Base); // <=== ERROR
}

so, I have base and derived classes, and want to use "using TBase::TBase" to pull copy ctor from base class to be able to create instance of derived class in such way:

   TDerived Derived(Base);

But all compilers rejects this with these error messages

7 : note: candidate constructor (the implicit copy constructor) not viable: no known conversion from 'TBase' to 'const TDerived' for 1st argument

Why? What am I doing wrong? Why "using TBase::TBase" does not work in this situation?

Aucun commentaire:

Enregistrer un commentaire