【发布时间】:2013-04-04 14:19:37
【问题描述】:
下面的代码给了我一个编译错误'value'没有在这个范围内声明。
template<class T>
struct Base {
int value;
};
template <class T>
struct Derived : public Base<T> {
int getValue() { return value; }
};
我觉得很奇怪
- 如果
Derived继承自Base<std::string>,则代码编译, - 如果我
return Base<T>::value,代码编译。
为什么代码不能按原样编译? Derived<T>::getValue()的范围内没有以什么方式声明'value'?
【问题讨论】: