c – 如何解决功能模板的部分专业化?

c – 如何解决功能模板的部分专业化?,第1张

概述例如,我有一个类: class A{ enum {N = 5}; double mVariable; template<class T, int i> void f(T& t) { g(mVariable); // call some function using mVariable. f<T, i+1>(t); // g 例如,我有一个类:
class A{    enum {N = 5};    double mVariable;    template<class T,int i>    voID f(T& t)    {        g(mVariable); // call some function using mVariable.        f<T,i+1>(t); // go to next loop    }    template<class T>    voID f<T,N>(T& t)    {} // stop loop when hit N.};

功能模板不允许部分专业化.在我的情况下,我该如何解决?

我略微改变了阿恩·默兹的例子,就像:

template<int n>struct A{    enum {N = n};    ...};

并使用A like:

A<5> a;

我无法在Visual Studio 2012上编译.它是编译器错误还是别的?这很奇怪

编辑:检查.它是一个Visual Studio的错误. 总结

以上是内存溢出为你收集整理的c – 如何解决功能模板的部分专业化?全部内容,希望文章能够帮你解决c – 如何解决功能模板的部分专业化?所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/langs/1253926.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-06-07
下一篇2022-06-07

发表评论

登录后才能评论

评论列表(0条)

    保存