1 #include <iostream>
2 using namespace std;
3 template<typename T>
4 class Top {
5 public:
6 class Sub {
7 protected:
8 T age;
9 };
10 class Derived : public Sub {
11 public:
12 void printAge() {
13 cout << age << endl;
14 }
15 };
16 };
17 int main()
18 {
19 return 0;
20 }
当我编译代码时,我收到以下错误:
test.cpp: In member function ‘void Top<T>::Derived::printAge()’:
test.cpp:13:25: error: ‘age’ was not declared in this scope
cout << age << endl;
但如果它不是一个模板,那就没问题了。我很高兴收到您的答复。