It works fine for non-template classes (the below code with the "template" lines commented out and deriving from Base, not Base<T>.
#include<iostream>
template<typename T>
class Base {
public:
int i_;
};
template<typename T>
class Deriv: public Base<T> {
public:
void foo() {
// This works.
std::cout << this->i_ << std::endl;
/* This fails:
tmpl.cc:14:18: error: ‘i_’ was not declared in this scope
std::cout << i_ << std::endl;
*/
std::cout << i_ << std::endl;
}
};
Why? And how do I fix it?