【问题标题】:tempate function into a non-templated class?模板函数到非模板类?
【发布时间】:2011-06-07 18:31:13
【问题描述】:

我想像这样将“模板化函数”添加到非模板化函数中:

class A
{
template <class T>
void Test<T>();
}

template <class T>
A::Test<T>();

但它告诉我 .h 文件中有错误!这个声明有问题吗?

备注:我的课程不得模板化!

谢谢

【问题讨论】:

  • 确切的错误信息是什么?
  • 我觉得你需要了解模板在C++中的作用
  • 七个问题,没有答案。不要以为我会在这个上发帖。

标签: c++ templates class function


【解决方案1】:

可以如下定义成员函数模板:

class A
{
    template <typename T>
    void Test()
    {
        ...
    };
};

【讨论】:

    猜你喜欢
    • 2010-12-20
    • 1970-01-01
    • 2011-07-30
    • 1970-01-01
    • 2012-03-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多