template <class T>
class Parent {
protected:
T _value;
};
template <class T>
class Child : public Parent<T> {
public:
void doStuff() { std::cout << _value << std::endl; }
};
GCC 6.3 gives
prog.cpp: In member function ‘void Child<T>::doStuff()’:
prog.cpp:14:33: error: ‘_value’ was not declared in this scope
void doStuff() { std::cout << _value << std::endl; }
^~~~~~
Using Parent<T>::_value
instead of _value
works. Why?
Reason for my confusion is that making Child
not a template works, too.
class Child : public Parent<int> {
public:
void doStuff() { std::cout << _value << std::endl; }
};
PS: On a side note, it compiles fine with MSVC in any case. I suspect that that is MSVC's fault, though.