草庐IT

c++ - cygwin 在 g++4.9.2 中支持 C++11

我正在尝试在Windows7下的cygwin下测试一些C++11代码,并且遇到以C++11开头定义的函数的编译错误,例如std::log2和std::round。我正在编译g++-std=c++11test.cpp,使用gcc4.9.2。这是一些无法编译的最小示例:#include#includeintmain(){autox=std::log2(10);std::cout错误:g++-std=c++11test.cpptest.cpp:Infunction‘intmain()’:test.cpp:5:11:error:‘log2’isnotamemberof‘std’autox=st

c++ - 通过 typedef : success at g++ , 强制模板实例化在 Visual C++ 中失败

我想强制模板实例化。以下代码在g++(http://coliru.stacked-crooked.com/a/33986d0e0d320ad4)下有效(print1)。但是,它在VisualC++(https://rextester.com/WGQG68063)中打印出错误的结果(0)。#include#includetemplatestructNonTypeParameter{};//internalimplementationintlala=0;templatestructHolder{staticintinit;};templateintHolder::init=lala++;/

c++ - g++ 4.3.4 编译器中的编译错误

#include#includechar*basename(constchar*filname);intmain(){return0;}char*basename(constchar*filename){char*base=(char*)filename;returnbase;}在g++4.1.220070115(SUSE10)上编译:没问题在g++4.3.4(SUSE11)上编译出现以下错误fileName:9:error:declarationofchar*basename(constchar*)抛出不同的异常fileName:3:error:frompreviousdeclara

c++ - C++11 库和 g++ 4.4.7 的问题

我正在使用GCC4.4.7版的服务器工作,不幸的是我被迫使用这个版本。我想利用C++0x的库,但我读了here在这个版本中uniform_real_distribution叫做uniform_real.当我尝试调用此函数和normal_distribution,我没有得到有用的输出。看这个例子:#include#includeusingnamespacestd;intmain(){typedefstd::mt19937Engine;typedefstd::uniform_realDis1;typedefstd::normal_distributionDis2;Engineeng(0);

c++ - G++ 与 Clang : inconsistent behavior for constexpr and const

考虑以下代码:constexprconstintA=42;constint&B=A;static_assert(&A==&B,"Bug");constexprconstint&C=B;static_assert(&A==&C,"Bug");intmain(){return0;}它被clang版本3.3完全接受,而g++(SUSELinux)4.8.120130909[gcc-4_8-branchrevision202388拒绝它:bug2.cpp:5:1:error:non-constantconditionforstaticassertionstatic_assert(&A==&B,

c++ - std::map 非常量仿函数,clang++ 下编译时错误,g++ 正常

我很好奇是否有人知道为什么g++编译下面的代码但是clang++给出错误。该代码创建一个std::map使用自定义排序仿函数SortCriterion.可以通过SortCriterion的构造函数指定排序类型:升序或降序。key比较通过operator()(int,int)实现.在g++下编译和运行一切正常,即使有-Wall,-Wextra,Wpedantic等等然而,clang++调用insert时出现错误功能,并提示const比较运算符的-ness,即想要operator()(int,int)const.note:candidatefunctionnotviable:'this'a

c++ - 编译器 g++ 无法创建 a.out 文件?

所以,我正在为我的C++类(class)做作业。我用这条语句编译了很长时间g++-5.2.0-std=c++14-Wall-Wextra-pedantic在终端时,出于某种我不知道的原因,我收到了这条消息:AgreeingtotheXcode/iOSlicenserequiresadminprivileges,pleasere-runasrootviasudo..天真地,我运行了命令sudog++-5.2.0-std=c++14-Wall-Wextra-pedantichw2pr3.cpp,输入我的密码,并同意条款。现在,当我尝试使用g++-5.2.0-std=c++14-Wall-W

c++ - 对类静态 constexpr 结构的 undefined reference ,g++ vs clang

这是我的代码,a.cp​​pstructint2{intx,y;};structFoo{staticconstexprintbar1=1;staticconstexprint2bar2={1,2};};intfoo1(){returnFoo::bar1;//thisisokforbothclang++andg++}int2foo2(){returnFoo::bar2;//undefinedreferenceto`Foo::bar2'inclang++}intmain(){std::cout使用clang编译,clang++-std=c++11a.cpp/tmp/a-0dba90.o:I

c++ - SFINAE:检测成员变量的存在在 g++ 上不起作用

我正在尝试结合thisanswer中使用的方法用于检测一个类是否有成员变量x与thisanswer根据使用enable_if选择不同的实现.基本上,我想写一个特征类,给定一个类型T,提供对成员T::x的访问如果存在,则提供默认值。以下代码无法在g++上编译:(CompilerExplorer)#include#include//classeswith/withoutxmemberstructWithX{staticconstexprintx=42;};structWithoutX{};//traittodetectxtemplatestructHasX:std::false_type{

c++ - 编译 fatal error 头文件g++

我遇到这个编译错误:fatalerror:can’tcreateprecompiledheaderf:Textfilebusycompilationterminated.这是一个非常神秘的东西,因为我只是偶尔得到它一次..我哪里出错了? 最佳答案 ETXTBSY是一个标准的errno值,我发现最好的解释是:Anattempttoexecuteafilethatiscurrentlyopenforwriting,orwritetoafilethatiscurrentlybeingexecuted.Oftenusingadebugger