Hi all,
I am a bit confused about the following piece of code (as a reduced part of an other problem, also related to templates):
Code:template< const int A > class Base { public: inline float getP() { return p; } protected: float p; }; template< const int B > class Child : public Base< B > { void member() { //this->p = 5.f; p = 5.f; } }; int main () { Child<4> myChild; myChild.getP(); return 0; }
When I use the inheritance
I am not allowed[1] to enter p without "this->":Code:template< const int B > class Child : public Base< B > {/* ... */};
template.cpp: In member function ‘void Child<B>::member()’:
template.cpp:15:5: error: ‘p’ was not declared in this scope
If I inherit via a specialization like
everything works out as normal.Code:class Child : public Base< 4 > {/* ... */};
Is there any explanation for this behaviour?
Do other compilers create the same error?
More Details:
- [1] compiled with:
Code:$ g++ -Wall template.cpp $ g++ --version g++ (Ubuntu/Linaro 4.5.2-8ubuntu4) 4.5.2
Chers and thanks a lot,
Axl



LinkBack URL
About LinkBacks



