| View previous topic :: View next topic |
| Author |
Message |
Larry Guest
|
Posted: Thu Apr 29, 2004 11:34 am Post subject: calling base class overloaded function |
|
|
Is there any way to call the original virtual function in the base
class that was overloaded through some special syntax like
super::func(), ::func() or something ? I'm thinking there may not be.
Sorry I'm a bit rusty on this type of thing.
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
|
|
| Back to top |
|
 |
llewelly Guest
|
Posted: Thu Apr 29, 2004 11:06 pm Post subject: Re: calling base class overloaded function |
|
|
[email]surfunbear (AT) yahoo (DOT) com[/email] (Larry) writes:
| Quote: | Is there any way to call the original virtual function in the base
class that was overloaded through some special syntax like
super::func(), ::func() or something ? I'm thinking there may not be.
[snip] |
You use the name of the base class before the ::.
struct base
{
virtual void foo(){}
virtual ~base(){}
};
struct derived:public base
{
virtual void foo(){base::foo();} //Like this.
};
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
|
|
| Back to top |
|
 |
Stephen C. Dewhurst Guest
|
Posted: Fri Apr 30, 2004 11:27 am Post subject: Re: calling base class overloaded function |
|
|
On 29 Apr 2004 07:34:09 -0400, [email]surfunbear (AT) yahoo (DOT) com[/email] (Larry) wrote:
| Quote: | Is there any way to call the original virtual function in the base
class that was overloaded through some special syntax like
super::func(), ::func() or something ? I'm thinking there may not be.
|
I think you may have meant to say "overridden" rather than
"overloaded" above, as in
struct B {
virtual void f() = 0;
};
void B::f() {}
struct D : public B {
void f(); // overrides and hides B::f, but
// does not overload it
};
This is a not uncommon scenario, where an overriding derived class
function wants to call the implementation of a (sometimes pure)
virtual base class function:
void D::f() {
B::f(); // non-virtual call
//...
}
Steve
www.semantics.org
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
|
|
| Back to top |
|
 |
Marco Oman Guest
|
Posted: Sat May 01, 2004 3:05 am Post subject: Re: calling base class overloaded function |
|
|
On 29 Apr 2004 19:06:36 -0400, llewelly <llewelly.at (AT) xmission (DOT) dot.com>
wrote:
| Quote: | surfunbear (AT) yahoo (DOT) com (Larry) writes:
Is there any way to call the original virtual function in the base
class that was overloaded through some special syntax like
super::func(), ::func() or something ? I'm thinking there may not be.
[snip]
struct derived:public base
{
virtual void foo(){base::foo();} //Like this.
};
[snip] |
In C++ D&E Stroustup talks about the proposal (not accepted)
to substitute the call
base::foo() ;
with a new keyword inherited (so the call would become inherited::foo())
The proposal was refused because one can add the line
typedef base inherited ;
and surrogate in this way the missing keyword.
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
|
|
| Back to top |
|
 |
|