草庐IT

c++ - G++ 不编译 C++0x 基于范围的 for 循环

我正在用G++试验一些新的C++0x特性。Lambdas、auto和其他新功能非常有效,但基于范围的for循环无法编译。这是我正在测试的程序:#include#includeintmain(){std::vectordata={1,2,3,4};for(intdatum:data){std::cout我编译它:g++test.cpp-std=c++0x我也试过gnu++0x,但输出是一样的。这是输出:test.cpp:Infunction‘intmain()’:test.cpp:8:21:error:expectedinitializerbefore‘:’tokentest.cpp:1

c++ - 使用 g++ 4.8 (Mac Ports) 在 Mac OS X 上编译 boost::program_options

我正在尝试编译boost::program_options示例之一,http://svn.boost.org/svn/boost/trunk/libs/program_options/example/first.cpp,使用gcc4.8(通过MacPorts安装)。但是,我不断收到错误消息:Undefinedsymbolsforarchitecturex86_64:"boost::program_options::to_internal(std::basic_string,std::allocator>const&)",referencedfrom:std::vector,std::a

c++ - 为什么 Microsoft 在其 DirectX10 管道变量中使用 "g_"命名约定?

Microsoft的DirectXSDK中的大多数示例代码都包含使用g_前缀作为WindowsAPI变量的变量,以及DirectX管道变量,例如交换链。以下是一些示例:D3D10_DRIVER_TYPEg_driverType;ID3D10Device*g_pd3dDevice;IDXGISwapChain*g_pSwapChain;ID3D10RenderTargetView*g_pRenderTargetView;ID3D10Effect*g_pEffect;ID3D10EffectTechnique*g_pTechnique;ID3D10InputLayout*g_pVertex

c++ - 有什么方法可以让 g++ 只发出与我的文件有关的警告?

我喜欢用-Wall编译我的代码,有时甚至用-pedantic。它部分是一种风格,部分是因为它偶尔会发出非常非常有用的警告(例如使用=而不是==)。然而,我的一些标题的作者显然不是这样的坚持者。使用两个警告级别中的任何一个进行编译都会产生大量困惑的输出,这完全违背了以这种方式进行编译的初衷。那么我怎样才能让我的编译器忽略这些警告呢? 最佳答案 替代JSBangs'answer,您可以让GCC将它们视为systemheaders,它会禁用这些header的所有警告(#warning指令除外)。如果-isystem开关没有帮助,您可以用仅

c++ - lambda 表达式(MSVC++ 与 g++)

我有以下代码#include#include#include#includeintmain(){typedefstd::vectorVector;intsum=0;Vectorv;for(inti=1;il=[&]()->double{std::for_each(v.begin(),v.end(),[&](intn){sum+=n;//ErrorHereinMSVC++});returnsum;};std::cout上述代码在MSVC++10上产生错误,而在g++4.5上编译良好。产生的错误是1IntelliSense:对lambda主体中外部作用域局部变量的引用无效c:\users\

c++ - g++ 警告,使用了内联虚函数但未定义

我目前遇到g++问题警告我无法摆脱。我的代码运行良好,但此警告不断弹出:ChildModel.h:136:24:warning:inlinefunctionvirtualintChildModel::getLinkCost(constLink&)constusedbutneverdefined[enabledbydefault]我目前找到了thispost在S.O上,有同样的问题,但答案是特定于库的(定义了一些东西)所以它对我不起作用。我的代码如下:classModel{public:virtualinlineintgetLinkCost(Linkconst&link)const;};

c++ - 这是 clang++/g++ 中的错误吗?

这个问题在这里已经有了答案:Whydoesthetemplate-idin"A=0"notcompilewithoutspacebecauseofthegreater-or-equal-thanoperator">="?(1个回答)关闭4年前。给定:voidfunction(int*=0){}intmain(){}clang(3.8.0):test.cc:1:18:error:expected')'voidfunction(int*=0){^g++(5.4.0):test.cc:1:18:error:expected‘,’or‘...’before‘*=’tokenvoidfuncti

c++ - 使用 g++ 编译器将目标文件生成到单独的目录 - C++

我使用以下代码将cpp文件编译为目标文件。g++-cmain.cpp以上代码在main.cpp所在的同一目录中生成.o文件。假设我有一个名为obj的文件夹,需要在那里生成目标文件,我该如何编写?如何查看g++支持的编译器开关及其用法?任何帮助都会很棒 最佳答案 SupposeIhaveafoldernamedobjandneedtogeneratetheobjectfilesthere,howdoIwrite?使用:g++-cmain.cpp-oobj/main.oHowcanIseethecompilerswitchessuppo

c++ - 为什么 g++ 不链接我创建的动态库?

我一直在尝试制作一些都依赖同一个库的应用程序,动态库是我的第一个想法:所以我开始编写“库”:/*ThinFS.h*/classFileSystem{public:staticvoidcreate_container(stringfile_name);//Createsanewcontainer};/*ThinFS.cpp*/#include"ThinFS.h"voidFileSystem::create_container(stringfile_name){cout然后我编译“库”g++-shared-fPICFileSystem.cpp-oThinFS.o然后我快速编写了一个使用该库

c++ - g++ "because the following virtual functions are pure"带抽象基类

这是我产生错误的示例代码:structImpl{intdata_size_;intfind(intvar){return0;}intget(introwid){return0;}};classContainer{public:Container(){}virtual~Container(){}virtualintget_size()=0;virtualintget(introwid)=0;};classSortedContainer:virtualpublicContainer{public:virtualintfind(intvar)=0;};classContainerImpl:p