Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Specializing Subclassed Methods

Reply
Thread Tools

Specializing Subclassed Methods

 
 
cppaddict
Guest
Posts: n/a
 
      06-03-2004
Hi,

How can you invoke a superclass's method from within the subclass
method that is overriding it?

For example, say that in the Car class we have a method like:

Car::turnOn() {
startEngine();
illuminateDashboard()
//other stuff
}

Now we want to specialize this method for a Corvette, which also flips
up its headlights when turned on. I'd like to do:

Corvette::turnOn() {
flipUpHeadlights();
super.turnOn()
}

But I know C++ does not support the super keyword like that. What is
the correct way to handle this situation?

Thanks,
cpp
 
Reply With Quote
 
 
 
 
Buster
Guest
Posts: n/a
 
      06-03-2004
cppaddict wrote:

> Hi,
>
> How can you invoke a superclass's method from within the subclass
> method that is overriding it?
>
> For example, say that in the Car class we have a method like:
>
> Car::turnOn() {
> startEngine();
> illuminateDashboard()
> //other stuff
> }
>
> Now we want to specialize this method for a Corvette, which also flips
> up its headlights when turned on. I'd like to do:
>
> Corvette::turnOn() {
> flipUpHeadlights();
> super.turnOn()
> }
>
> But I know C++ does not support the super keyword like that. What is
> the correct way to handle this situation?


Car::turnOn ();

// or

this->Car::turnOn ();

// or you can put

class Corvette : public Car
{
public:
typedef Car super;
// ...
};

// and use

super::turnOn ();

--
Regards,
Buster.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
calling methods of subclassed thread christoforever@gmail.com Ruby 3 10-09-2008 07:26 AM
what are the other ways to prevent a class from being subclassed. one way is to declare the class final. srinivas.veeranki@gmail.com Java 20 02-17-2006 12:21 AM
Subclassed ClassLoader problem with array types Benji Java 1 10-06-2005 10:00 AM
Is the URLConnection class capable of being subclassed to createcustom protocol connections? - Java 3 07-24-2005 06:39 PM
Cannot view subclassed Page in Visual Designer =?Utf-8?B?U2xpbWVtYW4=?= ASP .Net 4 07-20-2005 04:03 AM



Advertisments