为什么下面的代码没有编译?
#include <iostream>
template <class T>
class A
{
public:
T data;
};
template<typename T>
class B : public A<T>
{
public:
void foo(){printf("%d\n", data);}
};
int main()
{
B<int> b;
}
错误:
bla.cpp: In member function ‘void B<T>::foo()’:
bla.cpp:14:30: error: ‘data’ was not declared in this scope
void foo(){printf("%d\n", data);}
似乎成员变量&#34;数据&#34;因某种原因隐藏了。
答案 0 :(得分:0)
您可以通过this
this->data;