Board index Board index Board index
It is currently Sat Sep 22, 2018 11:57 am

All times are UTC - 5 hours [ DST ]




Post new topic Reply to topic  [ 5 posts ] 
Author Message
 Post subject: Hey Kup, can I ask for some help?
PostPosted: Thu Jun 23, 2005 2:43 pm 
Offline
Internet Activist and Superhero
User avatar

Joined: Tue Apr 01, 1997 11:00 am
Posts: 4028
Location: Palmsider
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?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 23, 2005 2:48 pm 
Offline
The Littlest Mod
User avatar

Joined: Mon Feb 05, 2001 3:02 am
Posts: 8467
Location: Blacksburg, Virginia
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.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 23, 2005 2:49 pm 
Offline
Internet Activist and Superhero
User avatar

Joined: Tue Apr 01, 1997 11:00 am
Posts: 4028
Location: Palmsider
Interesting. Wish Microsoft had thought to make that clear in the VC++ docs.

By the way, thanks.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 23, 2005 3:31 pm 
Offline
Internet Activist and Superhero
User avatar

Joined: Tue Apr 01, 1997 11:00 am
Posts: 4028
Location: Palmsider
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...


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 23, 2005 4:03 pm 
Offline
The Littlest Mod
User avatar

Joined: Mon Feb 05, 2001 3:02 am
Posts: 8467
Location: Blacksburg, Virginia
C# uses an <TT>override</TT> keyword, you might have seen it in that context.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC - 5 hours [ DST ]


Who is online

Users browsing this forum: No registered users and 6 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB

Localized by MaĆ«l Soucaze © 2010 phpBB.fr