The Shrine
http://www.tows.cc/phpBB2/

Hey Kup, can I ask for some help?
http://www.tows.cc/phpBB2/viewtopic.php?f=1&t=9323
Page 1 of 1

Author:  Nev [ Thu Jun 23, 2005 2:43 pm ]
Post subject:  Hey Kup, can I ask for some help?

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:
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?

Author:  Kupek [ Thu Jun 23, 2005 2:48 pm ]
Post subject: 

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.

Author:  Nev [ Thu Jun 23, 2005 2:49 pm ]
Post subject: 

Interesting. Wish Microsoft had thought to make that clear in the VC++ docs.

By the way, thanks.

Author:  Nev [ Thu Jun 23, 2005 3:31 pm ]
Post subject: 

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...

Author:  Kupek [ Thu Jun 23, 2005 4:03 pm ]
Post subject: 

C# uses an <TT>override</TT> keyword, you might have seen it in that context.

Page 1 of 1 All times are UTC - 5 hours [ DST ]
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/