#include <cstdio>
template<class T>
class A {
protected:
T x;
public:
A():x(5){}
};
template<class T>
class B:public A<T> {
public:
T tellX() {return x;}
};
int main() {
B<int> cl;
printf("%d\n",cl.tellX());
return 0;
}
When I try to compile it, I get:
d:\Docs\work\c++\TEST>g++ main.cpp -std=gnu++11
main.cpp: In member function 'T B<T>::tellX()':
main.cpp:13:21: error: 'x' was not declared in this scope
T tellX() {return x;}
^
What am I doing wrong? It works fine if I remove templates, but with them it breaks. How to fix it?