它适用于非模板类(以下代码使用"模板"行注释掉并从Base派生,而不是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;
}
};
为什么呢?我该如何解决?