#include <type_traits>#include <string>class A {public: A(const std::wstring&,const std::wstring&) {} template<typename T> A(const std::wstring& n,typename std::enable_if<std::is_arithmetic<T>::value,T>::type v) {}};int main() { A(L"n",1234); // does not compile A(L"n",2.7); // does not compile A(L"n",L"n"); // compiles return 0;}
错误on Ideone:模板参数扣除/替换失败
解决方法 你的T不可扣除(由于:: type),一种方法是:template<typename T,typename std::enable_if<std::is_arithmetic<T>::value>::type* = nullptr>A(const std::wstring& n,T v){}总结
以上是内存溢出为你收集整理的c – 使用enable_if将数字作为函数参数进行匹配全部内容,希望文章能够帮你解决c – 使用enable_if将数字作为函数参数进行匹配所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)