c – 模板别名不起作用

c – 模板别名不起作用,第1张

概述我正在尝试使用模板别名来处理clang,但它不起作用,尽管 reference sheet说它确实如此 ~~~~>$cat template_alias.cpp #include <vector>using namespace std;template<typename T>using DoubleVec = vector<vector<T>>;int main() { retur 我正在尝试使用模板别名来处理clang,但它不起作用,尽管 @L_403_0@说它确实如此

~~~~>$cat template_alias.cpp #include <vector>using namespace std;template<typename T>using Doublevec = vector<vector<T>>;int main() { return 0; }~~~~>$clang template_alias.cpp -o template_aliastemplate_alias.cpp:6:19: warning: alias declarations accepted as a C++0x extension [-Wc++0x-extensions]using Doublevec = vector<vector<T>>;                  ^template_alias.cpp:6:34: error: a space is required between consecutive right angle brackets (use '> >')using Doublevec = vector<vector<T>>;                                 ^~                                 > >template_alias.cpp:6:1: error: cannot template a using declarationusing Doublevec = vector<vector<T>>;^1 warning and 2 errors generated.~~~~>$clang -std=c++0x template_alias.cpp -o template_aliastemplate_alias.cpp:6:1: error: cannot template a using declarationusing Doublevec = vector<vector<T>>;^1 error generated.

我做错了吗?

解决方法 你的第二个命令(-std = c 0x)是正确的,你的测试用例也是如此.您可能在支持模板别名之前使用了clang版本.您可以通过执行以下 *** 作来检查:

#if __has_feature(cxx_alias_templates)

以下是clang使用的功能测试宏的完整列表:

http://clang.llvm.org/docs/LanguageExtensions.html#checking_upcoming_features

这是处理模板别名支持之间的过渡期的一种有点不愉快的方法,而不是:

#include <vector>using namespace std;#if __has_feature(cxx_alias_templates)template<typename T>using Doublevec = vector<vector<T>>;#elsetemplate<typename T>struct Doublevec {    typedef vector<vector<T> > type;};#endifint main(){#if __has_feature(cxx_alias_templates)    Doublevec<int> v;#else    Doublevec<int>::type v;#endif}
总结

以上是内存溢出为你收集整理的c – 模板别名不起作用全部内容,希望文章能够帮你解决c – 模板别名不起作用所遇到的程序开发问题。

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

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

原文地址: http://outofmemory.cn/langs/1214215.html

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

发表评论

登录后才能评论

评论列表(0条)

保存