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 

compiler error overloading function in CRTP context

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





PostPosted: Tue May 15, 2007 4:52 am    Post subject: compiler error overloading function in CRTP context Reply with quote



I don't understand why the compiler balks at the following:

//---------begin code -----------
template <typename T>
struct Base {
void foo() const {}
};

struct Derived : public Base<Derived> {
void foo(const int arg) const {}
};

int main(){
Derived d;
d.foo(15);
d.foo(); //won't compile... says that the "only candidate function
is void Derived::foo(int) "
}
//-----------end code -----------

It seems to me that the Derived::foo(int) should not hide Base::foo(),
but that's what appears to be happening. I've tried compiling with
IRIX gcc and Linux g++.

Can anyone explain why the compiler won't allow this?

Thanks in advance,
Daniel


--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
Back to top
John Moeller
Guest





PostPosted: Wed May 16, 2007 4:25 am    Post subject: Re: compiler error overloading function in CRTP context Reply with quote



John Moeller wrote:
Quote:
Base & b = d;

Oops, this should be Base<Derived>, not Base.

--

John Moeller
fishcorn (AT) gmail (DOT) com

[ 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.