【发布时间】:2016-09-01 19:38:50
【问题描述】:
我正在做一个小项目来了解 C++ 模板的工作原理。 基本上,我有类似的东西:
class Base{
public:
MyOperation<Base> operate(Base x){ return MyOperation<Base>(x); } //error here
};
//...
template<class B>
class MyOperation : public Base{
public:
B b;
MyOperation(B b_){ b = b_; }
};
当我尝试编译我的程序时,我收到一个错误(错误 C2143,在 '
提前谢谢你。
【问题讨论】:
-
这是
template(class B)的语法正确吗? -
编译器应该向您显示该行。通常,如果错误提及语法,则说明您搞砸了语法。在这里,你得到了
template(class B),而它应该是template<class B>。可能是你的伪代码,否则我会发布这个答案。 -
Base无法看到MyOperation,因为它是在Base之后定义的。 -
对不起,我在我的项目中写对了,
template<class B>
标签: c++ templates class-template