我希望我的模板派生类 der 继承自 foo。 这只是一个测试代码,我想看看我是否在这里采用了正确的方法 der 类本身是模板化的,我要做的是在初始化列表 der 类中传递其基类 foo 的模板类型。我正在使用以下代码
template<typename t , typename u>
struct foo
{
void foo_method(t inp , u out)
{
std::cout << inp + out << "\n";
}
};
template <typename m>
struct der : public foo<t,u> //Error t was not declared in the correct scope
{
der():foo<t,u>(int,int)//I want to specify the types for the base class in initialization list
{
}
};
int main()
{
der<std::string> d;
}
现在,当我尝试运行上面的代码时,我得到了
Error t was not declared in the correct scope
关于如何解决这个问题有什么建议吗?
最佳答案
我想这就是您要找的:
template <typename m>
struct der : public foo<int,int>
{
der():foo<int,int>()
{
}
};
关于c++ - 从另一个模板结构继承的模板结构,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27309094/