如何通过继承专门化复杂模板 - C++
我似乎找不到正确的语法来专门化此模板:
template <class Object, class Var, class Invert, class Step = Var, unsigned int FIXED = IW_GEOM_POINT>
class TSin : public BasicTween<Object, Var> {...
我想保留
template <class Object>
class TSin<Object, CIwVec2, int, CIwVec2, IW_GEOM_POINT> {...
这会产生错误。
请有人提供正确的语法来专门化模板和实例化专门版本的语法?
I can't seem to find the right syntax to specialize this template :
template <class Object, class Var, class Invert, class Step = Var, unsigned int FIXED = IW_GEOM_POINT>
class TSin : public BasicTween<Object, Var> {...
I want to keep <Object>
as a template parameter but specialize all other parameters. I am trying it like this :
template <class Object>
class TSin<Object, CIwVec2, int, CIwVec2, IW_GEOM_POINT> {...
This gives errors.
Please can someone provide the right syntax to specialize the template and the syntax to instantiate the specialized version?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我认为您的代码应该如下所示: http://ideone.com/cvGy3
您需要定义所有类型类实例化。
I think your code should look like here: http://ideone.com/cvGy3
You need to define all types for class instantiation.
错误是您正在重新定义
class TSin
。我认为你做不到。您可以做的是声明通用模板并专门化类的定义:
或专门化类成员的定义:
或声明子类:
我认为后一种选择是最好的。
The error is you're redefining
class TSin
. I don't think you can do that.What you can do is declare the generic template and specialize the definitions of the class:
or specialize the definitions of members of the class:
or declare a subclass:
I think the latter option is the best.