我在尝试使用模板继承时遇到了奇怪的错误。
这是我的代码:
template <class T> class A {
public:
int a {2};
A(){};
};
template <class T> class B : public A<T> {
public:
B(): A<T>() {};
void test(){ std::cout << "testing... " << a << std::endl; };
};
这是错误信息:
error: use of undeclared identifier 'a'; did you mean 'std::uniform_int_distribution<long>::a'?
void test(){ std::cout << "testing... " << a << std::endl; }
如果这会影响到我使用的某些内容,我会使用以下标志:
-Wall -g -std=c++11
我真的不知道问题出在哪里,因为与没有模板的纯类相同的代码正常工作。
void test(){ std::cout << "testing... " << A<T>::a << std::endl; };
- Rerito