The Other Worlds Shrine

Your place for discussion about RPGs, gaming, music, movies, anime, computers, sports, and any other stuff we care to talk about... 

  • Hey Kup, can I ask for some help?

  • Somehow, we still tolerate each other. Eventually this will be the only forum left.
Somehow, we still tolerate each other. Eventually this will be the only forum left.
 #89344  by Nev
 Thu Jun 23, 2005 2:43 pm
One of two things that I'd managed to miss in my C++ learning is how a method in a derived class that uses the override keyword differs from one that doesn't - e.g.:

Code: Select all
class Dorkus
{
    public void JibberJabber()
    {
         cout << "Quit yo' jibba-jabba!";
    }
}

class Doofus:  public Dorkus
{
    public override void JibberJabber()
    {
         cout << "I pity da fool who don' stop his jibba-jabba!";
    }
}


My understanding is that whether or not you specify the override keyword in declaring Doofus::JibberJabber, a call to Doofus::JibberJabber will override the implementation declared in Dorkus::JibberJabber - so, you'll get "I pity da fool who don' stop his jibba-jabba!" as output. If you want to call the base class code, you can put an explicit call to Dorkus::JibberJabber in the implementation of Doofus::JibberJabber.

What I don't get is exactly what the override keyword does. What difference does the override keyword make? Is it only for linking purposes?

 #89348  by Kupek
 Thu Jun 23, 2005 2:48 pm
There is no <TT>override</TT> keyword in C++. Overriding a member function is implicit; it happens if the member function in the derived class has the same signature (member function name and matching parameter types) as one in the base class. If you're using a keyword, then it's an extension in the compiler.

 #89349  by Nev
 Thu Jun 23, 2005 2:49 pm
Interesting. Wish Microsoft had thought to make that clear in the VC++ docs.

By the way, thanks.

 #89350  by Nev
 Thu Jun 23, 2005 3:31 pm
Am I on crack, or did I get catapulted into a parallel dimension? I could've sworn I'd used this in VC++ before, but it didn't even keyword when I typed it in. Oh well, full apology for Microsoft...*sigh*...so much for my credibility...

 #89351  by Kupek
 Thu Jun 23, 2005 4:03 pm
C# uses an <TT>override</TT> keyword, you might have seen it in that context.