我继承了派生类中的基类。这两个类都是模板。当我运行此代码时,编译器将引发以下错误:
'a':identifier not found
我想从基类中获取变量'a'。
#include "pch.h"
#include <iostream>
template <typename Type>
class Base
{
public:
int a;
Base()
{
a = 0;
std::cout << "Base";
}
};
template <typename Type>
class Derived :public Base<Type>
{
public:
int c;
Derived(int input)
{
c = input;
std::cout << "Derived";
}
void get_a()
{
std::cout << a;
}
};
int main()
{
Derived<int> obj(1);
obj.get_a();
}