【问题标题】:Instantiate a method template of a class template实例化类模板的方法模板
【发布时间】:2015-12-11 11:12:03
【问题描述】:

如何显式实例化以下 sn-p 的方法 f

template <int x> class A
{
public:
   template <typename T> inline void f(T y) { y = x; }
};

【问题讨论】:

  • 不确定你是否希望在你的函数中发生一些事情,但也许你应该传递一个引用f(T &amp; y) = { y = x; }
  • 嗯,那是一个什么都不做的毫无意义的例子。无论如何,感谢您的帮助。

标签: templates c++11 instantiation


【解决方案1】:

使用这个语法:

template void A<0>::f<int>(int);

显然用0int 替换您要实例化的内容。

【讨论】:

  • 这里允许使用“template ”而不是“template”的语法吗?
  • @Silicomancer 否,template&lt;&gt; 用于显式特化,而不是显式实例化。
  • 我们可以在这里删除显式的&lt;int&gt; 吗?
  • @alexolut 嗯,显然你可以。
猜你喜欢
  • 1970-01-01
  • 2020-12-27
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多