Jump to content
  • Advertisement
Sign in to follow this  
SSJCORY

C++ equivalent of the java super

This topic is 5070 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

In java if you did something like this: class monster{ ~~~~~~~~~~~~~~~~ public: void ShowInfo(){ cout<<"I am a monster."; } }; class greenmonster:public monster{ public: void ShowInfo(){ super.ShowInfo(); cout<<"and i am green!"; } }mona; The output upon calling mona.ShowInfo() would be I am a monster. and i am green! Is there a way to do this in c++?

Share this post


Link to post
Share on other sites
Advertisement
Certainly. Just qualify the name of the method with the name of the base class you're interested in (it can't be as simple as Java because C++ allows multiple inheritance). For example:

class A
{
public:
void do_something()
{
// ...
}
};

class B: public A
{
public:
void do_something()
{
// ...
A::do_something();
// ...
}
};

Of course, in such a case, it's good that A::do_something be virtual.

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.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!