So shortly the situation is like this
class Base
{
public:
Base() { setZero();}
virtual void setZero() {std::cout << "Set all Base class values to zeros (default) values";}
};
class Derived : public Base
{
public:
Derived () { }
void setZero() override {
Base::setZero();
std::cout << "Set all Derived class values to zeros (default) values";
}
};
setZero is public an is called form different places, also it has some logic, not just assignments, as Base and Derived classes are quite large. But it's all doesn't work as intended as dynamic binding doesn't work when function is called from the constructor. I see the solution to duplicate code from setZero to the consructors, but duplication of code is a bad thing. Is there some other solutions?
Aucun commentaire:
Enregistrer un commentaire