【问题标题】:Template method in template class with definition outside class模板类中的模板方法,类外定义
【发布时间】:2018-05-09 12:36:49
【问题描述】:

我想有一个模板类,里面有一个模板方法,并在类之外定义该方法。我试图四处寻找答案,但找不到答案。

例如:

template<typename A> class Type {
private:
    A value;
public:
    template<typename B> A Method(B value) {
        // some code here, it's not important for the sake of this example
    }
}

如何将方法Method 的定义移到类主体之外?提前致谢。

【问题讨论】:

    标签: c++ c++11 templates


    【解决方案1】:

    语法是

    template<typename A>
    template<typename B>
    A Type<A>::Method(B value)
    {
        // some code here, it's not important for the sake of this example
    }
    

    【讨论】:

      猜你喜欢
      • 2021-09-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-06-11
      • 1970-01-01
      • 2020-06-02
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多