草庐IT

const_defined

全部标签

c++ - 是什么导致 VS2013 错误 LNK2005 : __xi_a already defined in MSVCRT. lib(cinitexe.obj)?

我的解决方案是昨天构建的。今天,除了.hpp和.cpp文件外,它没有改变任何东西。VisualStudio2013的完整错误文本(使用2013年11月CTP):Error1errorLNK2005:__xi_aalreadydefinedinMSVCRT.lib(cinitexe.obj)C:\Users\drtwox\dev\repos\game\trunk\engine\game\LIBCMT.lib(crt0init.obj)gameError2errorLNK2005:__xi_zalreadydefinedinMSVCRT.lib(cinitexe.obj)C:\Users\

c++ - std::set<K, C>::operator<(const std::set<K, C>&) 不使用 C() 但 std::less()

无法删除我自己的问题,所以改写它... 最佳答案 这实际上不是实现中的错误,尽管它可以说是标准中的错误:23.2.1Generalcontainerrequirements[container.requirements.general]13Table98listsoperationsthatareprovidedforsometypesofcontainersbutnotothers.Thosecontainersforwhichthelistedoperationsareprovidedshallimplementtheseman

c++ - 使用 const 引用的函数模板重载决议

我试图理解以下情况下的重载决议规则:templatevoidf(constT&x){std::coutvoidf(T&x){//ÜberladungVariante2std::cout输出是:voidf(T&)[T=int]voidf(constT&)[T=int]据我所知,第一次调用f(e1)会导致可行的功能voidf(constint&)voidf(int&)从中选择第一个,因为没有删除const限定。第二次调用f(e2)导致类型推导/可行函数voidf(constint&);//T->intfromfirsttemplateoverloadvoidf(constint&);//T

c++ - Klocwork(或其他工具)能否识别类型、typedef 和#define 指令?

我使用lookingfor工具来解决helpdetect错误,这些错误阻止程序作为64位代码正常运行。最近,我一直在玩弄Klocwork及其自定义跳棋功能,它让我可以使用XPath将源代码作为树来导航。这作为正则表达式的“更智能”替代方案很有用,但我无法让它识别类型。例如,假设我想找到使用int或long的for循环的每个实例数数。下面的代码很容易找到。for(inti=0;i搜索这段代码很简单,因为变量定义就在循环内部。但是,请考虑以下示例。inti;//...for(i=0;i这很难找到,因为变量定义与循环是分开的,而且必要的XPath表达式要么笨拙,要么容易出错。那么,自定义Kl

c++ - 'auto' 关键字如何知道何时使用 const_iterator 匹配函数重载?

我了解thisquestion的内容但是当使用函数重载时,事情是如何工作的呢?例如在std::map中定义了以下方法:iteratorfind(constkey_type&k);const_iteratorfind(constkey_type&k)const;如何使用auto关键字来选择一个或另一个?以下内容对我来说似乎不正确:autoi=mymap.find(key);//callsthenon-constmethod?constautoi=mymap.find(key);//callstheconstmethod? 最佳答案 s

c++ - ‘const’ 错误之前的预期主表达式

请帮忙。我收到很多错误。sub2.cpp:在函数“intmain()”中:sub2.cpp:11:14:错误:从‘constchar*’到‘char’的无效转换[-fpermissive]sub2.cpp:12:14:错误:从‘constchar*’到‘char’的无效转换[-fpermissive]sub2.cpp:16:17:错误:'const'之前需要主表达式sub2.cpp:16:36:错误:'const'之前需要主表达式sub2.cpp:11:6:警告:未使用的变量“外部”[-Wunused-variable]sub2.cpp:12:6:警告:未使用的变量‘inner’[-W

c++ - 当底层 OpenGL 状态被修改时,我是否应该声明一个方法 const

下面的类封装了缓冲区的OpenGL名称,并提供了一些改变缓冲区状态的方法:classBufferObject{public:explicitBufferObject(GLenumtype);virtual~BufferObject();//somemethodsomittedvoiddataStore(GLsizeiptrsize,constGLvoid*data,intusage);void*mapBufferRange(GLintptroffset,GLsizeiptrlength,intaccessFlag);voidunmapBuffer()const;private:GLui

c++ - 使用对 const char * 的右值引用的重载解析

#includeusingnamespacestd;voidf(constchar*const&s){cout输出:rvaluervalue为什么输出不是“右值左值”? 最佳答案 字符串文字和s都不是指针(它们是数组),因此标准的相关部分是[conv.array]:Anlvalueorrvalueoftype"arrayofNT"or"arrayofunknownboundofT"canbeconvertedtoaprvalueoftype"pointertoT".Theresultisapointertothefirsteleme

c++ - 有 const 构造函数这样的东西吗?

今天我不小心把const放在我的构造函数的开头(复制粘贴错误)并且它编译了。我只在C++11之前的VisualStudio2008中试过这个。这个语法有什么意义吗?这是微软在constexpr上的早期尝试吗?classfoo{public:constfoo(inti){}};foof(1); 最佳答案 您的代码不符合标准,没有这样的东西。但是,从C++11开始,您可以拥有constexpr构造函数,因此您的对象是在编译时构造的,并且可以进一步在constexpr表达式中使用。虽然我没有使用它,但就标准合规性而言,MSVS并不是最好的

c++ - 为什么 `constexpr const int &a = 1;` 在 block 范围内失败?

N45277.1.5[dcl.constexpr]p9Aconstexprspecifierusedinanobjectdeclarationdeclarestheobjectasconst.Suchanobjectshallhaveliteraltypeandshallbeinitialized.Ifitisinitializedbyaconstructorcall,thatcallshallbeaconstantexpression(5.20).Otherwise,orifaconstexprspecifierisusedinareferencedeclaration,everyf