草庐IT

GCC_NO_COMMON_BLOCKS

全部标签

c++ - 全局函数和不明确的参数 NULL 与 char* 在 vs 2013 和 GCC 之间

我试图了解当前C++14标准关于解决模糊函数调用的内容,主要是因为我看到GCC4.9.1和VisualStudio2013更新3之间的差异这是代码(MS和GCC完全相同):#includeusingnamespacestd;voidf(char*str,intchars){coutVisualStudio使用默认vs标志调用f(char*,int)GCC给了我一个编译器错误:重载'f(char*&,NULL)'的调用不明确。gcc仅使用-std=c++11标志。 最佳答案 这取决于NULL的定义。MSVC将其定义为0,因此int重载

c++ - 不鼓励使用 GCC

header保护在几乎所有C++程序中都是必需的,但在严格执行命名约定时会很痛苦——尤其是在重构过程中。当使用GCC(和许多其他编译器)时,我们在预处理器命令#pragmaonce中有一个替代方案。我看到的反对使用此命令的建议(例如,在v3.4之前缺乏支持)对于我的个人项目来说并不是很有说服力。如果可能,我想使用#pragmaonce。综上所述,这句话来自theGCCwebsite让我暂停:Notethatingeneralwedonotrecommendtheuseofpragmas;SeeFunctionAttributes,forfurtherexplanation.也许这只是我

c++ - 错误 : no matching function for call to ‘to_string(std::basic_string<char>&)’

即使在模板中我可以有任何类型,函数to_string对基本字符串不起作用:例如:std::stringstr("mystring");my_class(str);用这个仿函数定义:templatevoidoperator()(valuetypevalue){...private_string_field=std::to_string(value);不起作用。这是错误:error:nomatchingfunctionforcallto‘to_string(std::basic_string&)’避免它的最佳方法是什么。事先,我要求避免仅仅因为一些常见的关键字就链接到不相关的问题。

c++ - "no matching function for call to ‘async(std::launch, <unresolved overloaded function type>, std::string&)’“

我正在尝试使用std::async创建线程,但我不断收到错误“没有匹配函数调用‘async(std::launch,,std::string&)’”在行上ConnectFuture=std::async(std::launch::async,Connect_T,ip);这是产生这种行为的代码:#includeclasslibWrapper{public:voidConnect(std::stringip);voidConnect_T(std::stringip);private:std::futureConnectFuture;};voidlibWrapper::Connect(std

c++ - sscanf 中 uint16_t 的正确且可移植的 (Clang/GCC) 修饰符是什么?

当我尝试编译这段代码时收到一条警告消息sscanf(value,"%h"PRIu16"B",&packet_size)使用Clang600.0.57(OSX)。warning:formatspecifiestype'unsignedchar*'buttheargumenthastype'uint16_t*'(aka'unsignedshort*')[-Wformat]if(sscanf(value,"%h"PRIu16"B",&packet_size)==1){~~~~^~~~~~~~~~~~但是如果我删除修饰符“h”,那么我会在GCC4.8.3(ScientificLinux7)中收

c++ - 警告 C4661 :no suitable definition provided for explicit template instantiation request

我写了一个类模板并在不同的DLL中使用它,所以希望隐藏部分实现。为此,我使用“模板实例化”,但导出它,像这样,这里是头文件:#include#includeusingnamespacestd;templateclass__declspec(dllexport)Templated{public:Templated();};template__declspec(dllexport)Templated;intmain(){cout并且定义在单独的文件(.cpp)中templateTemplated::Templated(){}templateTemplated;我的问题是我收到警告,即使实例

c++ - 为什么下面的代码不能用 gcc 编译但用 clang 编译得很好

下面的代码可以用clang编译,但不能用gcc编译,请问这是gcc中的错误吗?它只是一个包含unique_ptrvector和std::function作为成员的类,当我创建此类的vector时,我不能对此说保留或调整大小。push_back与std::move一起工作正常,而这只发生在gcc而不是clang上。#include#include#include#include#include#includeusingnamespacestd;classABC{public:ABC(){}private:std::vector>up;std::functionfunc;};intmain

c++ - 错误 : no matching member function for call to 'push_back'

为什么我在最后两行收到错误?目标是在集合中找到对象,并修改其内容。usingnamespacestd;structmystruct{intid;vectory;mystruct(constintid):id(id){}booloperatorsx;mystructx(1);x.y.push_back(1);x.y.push_back(2);sx.insert(x);//set::iteratori=sx.find(1);constmystruct*x1=&(*i);constmystructx2=*x1;couty)y)y.push_back(4);}好像迭代器返回的是常量对象,不让我

c++ - 你能初始化 unique_ptr 的 "static const vectors"吗? (C++17 与 GCC 7.3)

我正在尝试创建一个staticconst默认对象(规则)的列表太大而不能经常复制,因此我想将它们存储在vector中的unique_ptr.我注意到类似的问题已经进行了几次,但我不清楚这是否真的可行(我倾向于不可行)。即你不能使用initializer_list与unique_ptr因为对成员的访问是const导致复制操作。您不能通过引用传递临时变量,从而导致复制操作。因此两者:staticconststd::vector>kStrings={std::unique_ptr(newstd::string("String1")),std::unique_ptr(newstd::strin

c++ - 错误 : no matching function for call to . .. 在返回语句

我在openSUSELeap15上的Qt5.9.4上使用GCC7。我有以下类(class):classManSuppProps:publicQObject{Q_OBJECTpublic:explicitManSuppProps(QStringparentName);explicitManSuppProps(){}explicitManSuppProps(constManSuppProps&manSuppProps);explicitManSuppProps(ManSuppProps&manSuppProps);~ManSuppProps();private:QVector3Dm_sup