J
Jaco Naude
Hi
Not sure if this is a stupid question, but here it goes:
Is it possible to call a virtual method in the derived class from a
base class? I know that the method can be made abstract but then the
whole class also becomes and abstract base class.
class BaseClass {
virtual bool method(bool call_derived) {
if (call_derived)
// I want to call method() in DerivedClass without knowing
anything about it.
else
return false;
}
}
class DerivedClass : public BaseClass {
bool method() { return true; }
}
Thus when I do this in my main function:
BaseClass base;
base.method(true); // Should return true;
base.method(false); // Should return false;
Is this even possible at all? Or is the only way to do this by
declaring method() = 0 in the base class (like a normal interface
class).
Thanks,
Jaco
Not sure if this is a stupid question, but here it goes:
Is it possible to call a virtual method in the derived class from a
base class? I know that the method can be made abstract but then the
whole class also becomes and abstract base class.
class BaseClass {
virtual bool method(bool call_derived) {
if (call_derived)
// I want to call method() in DerivedClass without knowing
anything about it.
else
return false;
}
}
class DerivedClass : public BaseClass {
bool method() { return true; }
}
Thus when I do this in my main function:
BaseClass base;
base.method(true); // Should return true;
base.method(false); // Should return false;
Is this even possible at all? Or is the only way to do this by
declaring method() = 0 in the base class (like a normal interface
class).
Thanks,
Jaco