Jump to content
  • Advertisement
Sign in to follow this  
Kalasjniekof

inheritance

This topic is 4793 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, say I have these two classes:
class MyClass
{
  virtual DoSomething() {//code}
}

class MyDerivedClass: public MyClass
{
  DoSomething(){//additional code}
}

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?

Share this post


Link to post
Share on other sites
Advertisement
you can still use the functions available in the inherited class, meaning that you can call the inherited "DoSomething", from your own "DoSomething".

Share this post


Link to post
Share on other sites
Well it's more than just one keyword, but...

class MyClass
{
virtual DoSomething() {
//code
}
}

class MyDerivedClass: public MyClass
{
DoSomething() {
MyClass::DoSomething();
//additional code
}
}

Share this post


Link to post
Share on other sites
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
}
};

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!