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 

Deriving from a templated base class

 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language (comp.lang.c++)
View previous topic :: View next topic  
Author Message
Guest






PostPosted: Sat Oct 28, 2006 9:10 am    Post subject: Deriving from a templated base class Reply with quote



Hello,

I have the following code
---
template < typename T>
struct Base
{
T base_member;
};

template < typename T>
struct Child: public Base <T>
{
T myfunc(){ return base_member; }
};

int main(){
Child<int> child;
return 0;
}
---
To my surprise it does not appear to compile (using g++ 3.4):
temptest1.cpp: In member function `T Child<T>::myfunc()':
temptest1.cpp:10: error: `base_member' was not declared in this scope

However changing the myfunc() line to

T myfunc(){ return Base<T>::base_member; }

makes it work fine. Does anyone know why i have to explicitly define
the namespace ? I don't understand why it should be ambigous which
base_member i mean, since there's only one base class ? Is there a way
to make it work implicitly ?

Thanks for any help,

Mike
Back to top
Display posts from previous:   
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language (comp.lang.c++) 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.