473,326 Members | 2,173 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

Specializing Subclassed Methods

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
Jul 22 '05 #1
1 1045
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.
Jul 22 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Jeff | last post by:
/* -------------------------------------------------------------------------- Hello, I was experimenting with class templates and specializing member functions and came across a simple problem...
5
by: Exits Funnel | last post by:
I've got this code: //Begin foo.cpp #include <utility> #include <bits/stl_function.h> typedef std::pair<int, int> int_pair_t; template<> struct std::less<int_pair_t> { };
2
by: Alex Drummond | last post by:
Hello, Is there any way of specializing a templated function on a type which is itself templated? Here's the simplest example of the problem I can think of. Say I have written an implementation...
3
by: CJM | last post by:
I'm currently working on an assembly that has both forms and controls in it. When I create a new control based on UserControl and compile, it shows up in the toolbox for all forms in this...
3
by: abiz | last post by:
What is the current thinking about specializing generic C# types? I've come across a situation where I'd like to do something like this: struct X<T,U> { ... } struct XCommonCase<T=...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.