C ++模板类模板功能问题 [英] C++ template class template function question

查看:82
本文介绍了C ++模板类模板功能问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在模板类B中添加一个以S作为模板参数的成员函数Y.

I want to add a member function Y that takes S as a template parameter in template class B.

template<typename t="">
class B {
public:
   template<typename s="">
   static void X(S & x);
}
</typename></typename>



如果我尝试定义



If I try to define

template<>
template<typename s="">
void B<_variant_t>::X(S & x) {
}
</typename>







or

<pre>
template<typename t="">
template<typename S>
void B<t>::X(S & x) {
}
</pre></t></typename>




我收到错误消息




I get an error

推荐答案

您要查找的是模板函数,而不是模板类.更确切地说,这与是否声明类模板无关.您的职能可以保持不变或成为班上的一员;此类可以是模板类,也可以不是.

回顾一些有关如何编写模板函数的示例:
http:///publib.boulder.ibm.com/infocenter/comphelp/v8v101/index.jsp?topic=%2Fcom.ibm.xlcpp8a.doc%2Flanguage%2Fref%2Ffunction_templates.htm [
What you are looking for is template function, not template class. More exactly, this is irrelevant if the declaring class template or not. You function can stay along or be a member of the class; and this class can be a template class or not, does not matter.

Review some samples on how to write a template function:
http://publib.boulder.ibm.com/infocenter/comphelp/v8v101/index.jsp?topic=%2Fcom.ibm.xlcpp8a.doc%2Flanguage%2Fref%2Ffunction_templates.htm[^].

It should be enough, but you can find tons of info if you Google for it.

—SA


这篇关于C ++模板类模板功能问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆