如何通过继承专门化复杂模板 - C++

发布于 2024-11-25 08:44:05 字数 468 浏览 1 评论 0原文

我似乎找不到正确的语法来专门化此模板:

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

眉目亦如画i 2024-12-02 08:44:05

我认为您的代码应该如下所示: 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.

何以笙箫默 2024-12-02 08:44:05

错误是您正在重新定义 class TSin。我认为你做不到。

您可以做的是声明通用模板并专门化类的定义:

template <class Object, class Var, class Invert, class Step = Var, 
    unsigned int FIXED = IW_GEOM_POINT>
    class TSin;
template <class Object>
    class TSin<Object, CIwVec2, int, CIwVec2, IW_GEOM_POINT> {...

或专门化类成员的定义:

template <class Object>
void TSin<Object, CIwVec2, int, CIwVec2, IW_GEOM_POINT>::Foo(...) {...

或声明子类:

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 SpecialTSin::public TSin<Object, CIwVec2, int, CIwVec2, IW_GEOM_POINT>
{...

我认为后一种选择是最好的。

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:

template <class Object, class Var, class Invert, class Step = Var, 
    unsigned int FIXED = IW_GEOM_POINT>
    class TSin;
template <class Object>
    class TSin<Object, CIwVec2, int, CIwVec2, IW_GEOM_POINT> {...

or specialize the definitions of members of the class:

template <class Object>
void TSin<Object, CIwVec2, int, CIwVec2, IW_GEOM_POINT>::Foo(...) {...

or declare a subclass:

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 SpecialTSin::public TSin<Object, CIwVec2, int, CIwVec2, IW_GEOM_POINT>
{...

I think the latter option is the best.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文