 |
C++Talk.NET C++ language newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Guest
|
Posted: Sat Oct 28, 2006 9:10 am Post subject: Deriving from a templated base class |
|
|
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 |
|
 |
|
|
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
|
|