dimanche 1 février 2015

Use parent class constructor for child

So, I want to have class Child that has all constructors from its parent class. Is this possible in C++? I have tried using statement, but it wont work. Here's what I've got so far:



struct Base{
Base(int i){
std::cout << "Construcetd a base with " << i << std::endl;
}


};


struct Child : public Base{
using Base::Base;

};




int main(){

Child c(1);
}


Error that I'm getting:



error C2664: 'Child::Child(const Child &)' : cannot convert argument 1 from 'int' to 'const Child &'

Aucun commentaire:

Enregistrer un commentaire