c – 代码在g上编译并带有警告,但在clang3.1(Xcode 4.3.3)上的相
以下行在g上成功编译但在clang上给出错误::
static_assert(tBits <= sizeof(ULONG)*8,"This is IO method"); g警告::
铿锵错误::
请帮帮我. 评论中的函数声明: template < size_t tBits > HRESULT DoIO( std::bitset< tBits >& bitsetToSerialize ) const 解决方法
“static_assert”在C 11中作为语言关键字引入 – 不是函数或宏.
两个编译器都给你“我不知道这个函数”的警告/错误. 当您使用“static_assert”时编译器为您提供“我不知道此函数”,编译器不能使用C 11支持进行编译(-std = c 11). 为了证明这一点,我采用了以下代码: #include <bitset> template<size_t tBits> int DoIO(std::bitset<tBits>& /*bitsetToSerialize*/) { static_assert(tBits <= sizeof(unsigned long) * 8,"tBits is too big."); return tBits; } 然后我用GCC 4.7.3编译它,我得到以下错误: osmith@olivia64 ~/src $g++ -o sa.o -c sa.cpp sa.cpp: In function ‘int DoIO(std::bitset<_Nb>&)’: sa.cpp:6:78: error: there are no arguments to ‘static_assert’ that depend on a template parameter,so a declaration of ‘static_assert’ must be available [-fpermissive] sa.cpp:6:78: note: (if you use ‘-fpermissive’,G++ will accept your code,but allowing the use of an undeclared name is deprecated) 然后我在启用C 11支持的情况下编译它并编译没有问题: osmith@olivia64 ~/src $g++ -std=c++11 -o sa.o -c sa.cpp -Wall osmith@olivia64 ~/src $ 所以,然后我用Clang编译它 osmith@olivia64 ~/src $clang++ -o sa.o -c sa.cpp sa.cpp:6:9: error: use of undeclared identifier 'static_assert'; did you mean 'static_cast'? static_assert(tBits <= sizeof(unsigned long) * 8,"tBits is too big."); ^ 1 error generated. 最后我使用Clang C 11支持编译它,编译得很好. osmith@olivia64 ~/src $clang --version Ubuntu clang version 3.2-1~exp9ubuntu1 (tags/RELEASE_32/final) (based on LLVM 3.2) Target: x86_64-pc-linux-gnu Thread model: posix osmith@olivia64 ~/src $clang++ -std=c++11 -o sa.o -c sa.cpp osmith@olivia64 ~/src $ 只是为了确定,让我们给编译器机会来帮助我们并打开“-Wall”: osmith@olivia64 ~/src $g++ -Wall -o sa.o -c sa.cpp sa.cpp:6:9: warning: identifier ‘static_assert’ is a keyword in C++11 [-Wc++0x-compat] sa.cpp: In function ‘int DoIO(std::bitset<_Nb>&)’: sa.cpp:6:78: error: there are no arguments to ‘static_assert’ that depend on a template parameter,but allowing the use of an undeclared name is deprecated) (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
- Cocos2dx学习笔记(1) Ref类型数据 垃圾回收机制
- Ruby,Mongodb,Anemone:网络爬虫可能有内存泄漏?
- c# – 使用文件上传控件过滤文件类型
- 帮助你高效开发Ajax应用的超酷jQuery插件 - AjaxML
- 使用vue和datatables进行表格的服务器端分页实例代码
- 在C#中计算重复日期的正确方法
- Halcon 学习总结——电子加密狗字符检测(ocr_dongle)
- reactjs – React Native使用什么来允许JavaScript在iOS和A
- ruby-on-rails – Rails中的Angular ui bootstrap自定义模板
- React Redux: 从文档看源码 - Connect工具类篇(1)