class MyClass
{
virtual DoSomething() {//code}
}
class MyDerivedClass: public MyClass
{
DoSomething(){//additional code}
}
inheritance
Hi, say I have these two classes:
Would it be possible to let the MyDerivedClass::DoSomething() member to (automatically) include the code of MyClass::DoSomething() (e.g. like the "inherited" keyword in delphi)? Or should I just copy the code in my editor?
you can still use the functions available in the inherited class, meaning that you can call the inherited "DoSomething", from your own "DoSomething".
Well it's more than just one keyword, but...
class MyClass{ virtual DoSomething() { //code }}class MyDerivedClass: public MyClass{ DoSomething() { MyClass::DoSomething(); //additional code }}
Not really, but if you really want to do something like that, then it's likely that a different idiom would work out:
class MyClass { public: void DoSomething(void) { // not virtual // code DoSomethingImpl(); } private: virtual void DoSomethingImpl() {} // potentially pure virtual};class MyDerivedClass : public MyClass { private: virtual void DoSomethingImpl() { // derived class' behaviour }};
constructors/destructors are automatically called when inherited, using "super" you can call them with custom arguments if necesarry.
REMEMBER to make the destructor virtual if you want to be safe.
REMEMBER to make the destructor virtual if you want to be safe.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement