C++Talk.NET Forum Index C++Talk.NET
C++ language newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

calling base class overloaded function

 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ Language (Moderated)
View previous topic :: View next topic  
Author Message
Larry
Guest





PostPosted: Thu Apr 29, 2004 11:34 am    Post subject: calling base class overloaded function Reply with 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.


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





PostPosted: Thu Apr 29, 2004 11:06 pm    Post subject: Re: calling base class overloaded function Reply with quote



[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





PostPosted: Fri Apr 30, 2004 11:27 am    Post subject: Re: calling base class overloaded function Reply with quote



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





PostPosted: Sat May 01, 2004 3:05 am    Post subject: Re: calling base class overloaded function Reply with quote

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
Display posts from previous:   
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ Language (Moderated) All times are GMT
Page 1 of 1

 
Jump to:  
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 vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.