Page 1 of 1

Hey Kup, can I ask for some help?

PostPosted:Thu Jun 23, 2005 2:43 pm
by Nev
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?

PostPosted:Thu Jun 23, 2005 2:48 pm
by Kupek
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.

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

By the way, thanks.

PostPosted:Thu Jun 23, 2005 3:31 pm
by Nev
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...

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