草庐IT

c++ - g++ vs intel/clang 参数传递顺序?

考虑以下代码(LWS):#include#includeinlinevoidtest(conststd::chrono::high_resolution_clock::time_point&first,conststd::chrono::high_resolution_clock::time_point&second){std::cout您必须多次运行它,因为有时并没有明显的区别。但是当first和second的计算时间存在明显差异时,g++下的结果如下:13633762393631751363376239363174以及intel和clang下的以下内容:13633762679714

c++ - "expected nested-name-specifier before ‘const’ 错误“在 g++ 中类型名称为 const

我在C++中有这段代码templateclassDD:publicenumerables{...private:typenameconstDD&mContainer;}它给了我两条错误信息:错误:在“const”之前需要嵌套名称说明符错误:“&”标记前的声明符无效typenameconst有什么问题?代码?它使用MSVCC++编译得很好。已添加typenameDD&constmContainer;和consttypenameDD&mContainer;给我同样的错误。 最佳答案 那么,typename在那里做什么?您指的不是嵌套类型

c++ - g++ 预处理器输出

很难说出这里要问什么。这个问题模棱两可、含糊不清、不完整、过于宽泛或夸夸其谈,无法以目前的形式得到合理的回答。如需帮助澄清此问题以便重新打开,visitthehelpcenter.关闭10年前。我只想获取file.cc的预处理版本。我做了g++-Efile.cc,得到:#1"file.cc"#1""#1"file.cc"我做错了什么?

c++ - "undefined reference to"使用'g++'编译C++程序

我似乎无法让错误消失。错误如下。我已经查看了Google搜索,但仍然无法弄清楚。我不是C++新手,但我已经有一段时间没有玩弄它了。奇怪的是它在Windows上与g++一起工作...错误使用:g++main.cpp输出:/tmp/ccJL2ZHE.o:Infunctionmain':\main.cpp:(.text+0x11):undefinedreferencetoHelp::Help()'main.cpp:(.text+0x1d):undefinedreferencetoHelp::sayName()'\main.cpp:(.text+0x2e):undefinedreference

c++ - std::array 在 g++ 上进行聚合初始化会生成大量代码

在g++4.9.2和5.3.1上,这段代码需要几秒钟的时间来编译并生成一个52,776字节的可执行文件:#include#includeintmain(){constexprstd::size_tsize=4096;structS{floatf;S():f(0.0f){}};std::arraya={};//增加size似乎会线性增加编译时间和可执行文件的大小。我无法使用clang3.5或VisualC++2015重现此行为。使用-Os没有任何区别。$timeg++-O2-std=c++11test.cppreal0m4.178suser0m4.060ssys0m0.068s检查汇编代

c++ - 为什么这是 g++8 的非常数条件?

我有这个代码。这是一个我可以在编译时使用的数组(有点像std::array)。也在编译时进行for循环。#include#include#includetemplateconstexprvoid__loop(F&&func,std::index_sequence)noexcept{(func(std::integral_constant{}),...);}templateconstexprvoidCONSTEXPR_LOOP(F&&func)noexcept{__loop(std::forward(func),std::make_index_sequence());}templatec

c++ - g++ 和 clang++ 在 `std::make_index_sequence` 和 `std::index_sequence` 用于模板参数默认类型时的不同行为

另一个“g++和clang++之间谁是正确的?”C++标准专家的问题。给定以下代码#includetemplate>structfoo;templatestructfoo>{};templatevoidbar(fooconst&){}intmain(){bar(foo{});}我看到g++编译时clang++给出了以下错误tmp_003-14,gcc,clang.cpp:32:4:error:nomatchingfunctionforcallto'bar'bar(foo{});^~~tmp_003-14,gcc,clang.cpp:27:6:note:candidatetemplate

c++ - static_assert 无法将 const char* 模板参数识别为 constexpr : g++ bug?

考虑以下定义。charright_string[]="::right_one.";charwrong_string[]="::wrong_one.";templatevoidf(){static_assert(str==::right_string,"Passme::right_string!");}structTest{staticconstexprcharright_string[]="template_struct::right_one";staticconstexprcharwrong_string[]="template_struct::wrong_one";template

c++ - clang++/g++/gfortran之间的简单测试用例

我在scicomp上遇到了这个问题这涉及计算总和。在那里,你可以看到c++和类似的fortran执行。有趣的是,我看到Fortran版本的速度提高了大约32%。我想,我不确定他们的结果,并试图重振局面。这是我运行的(非常轻微的)不同代码:C++#include#include#include#includeintmain(){constdoublealpha=1;std::cout.precision(16);std::complexsum=0;conststd::complexa=std::complex(1,1)/std::sqrt(2.);for(unsignedintk=1;k

c++ - 是可调用和模糊调用 : bug in either g++ or clang

考虑以下代码://Preamble#include#include//Abaseclasstemplatestructbase{voidoperator()(T){};};//Twoderivedclassesinheritingfromthesamebaseclassestemplatestructderived1:base...{usingbase::operator()...;};templatestructderived2:base...{usingbase::operator()...;};//Aclassinheritingfrombothderived1andderive