草庐IT

non-virtual

全部标签

C++ 编译器错误 "cannot be thread-local because it has non-POD type”“

这个声明:___threadAa;生成此错误:cannotbethread-localbecauseithasnon-PODtypeA在哪里classA{public://functiondeclarationprivate://datamembers};我正在尝试使用命令ogsincludes&ogsmk在Linux上进行编译。我们有静态线程,即在我们的应用程序进入之前,我们知道线程的数量,因此目前的工作是通过声明A的数组来完成的,即Aa[Numberofthreads].我该如何解决这个问题? 最佳答案 假设您使用gcc,线程本

c++ - 使用 protected 非虚拟析构函数时抑制 delete-non-virtual-dtor 警告

我有一个纯抽象接口(interface)类和一个实现该接口(interface)的派生类。structFoo{virtualvoiddoStuff()=0;};structBar:Foo{voiddoStuff()override{}};我的接口(interface)类没有虚拟析构函数。因此,尝试使用基类指针破坏派生实例显然是未定义的行为intmain(){Foo*f=newBar;f->doStuff();deletef;}幸运的是我的编译器足够聪明,可以捕捉到这个(使用-Werror)main.cc:15:9:error:deletingobjectofabstractclasst

c++ - _wtoi 返回零 : input zero or non-numerical input?

_wtoi当不能转换输入,所以输入不是整数时,返回零。但同时输入可以为零。这是一种确定输入是否错误或为零的方法吗? 最佳答案 这是C++,您应该使用stringstream进行转换:#include#includeintmain(){usingnamespacestd;strings="1234";stringstreamss;ss>i;if(ss.fail()){throwsomeWeirdException;}coutboost的lexical_cast有一个更简洁、更简单的解决方案:#include//...std::stri

c++ - 如何解决 : undefined reference to `non-virtual thunk to ...`

我正在尝试弄清楚如何进一步解决此问题。我还想知道如何安装更新版本的ld(如果有意义的话)。所有涉及的包管理器都告诉我,我是最新的。代码在ubuntu12.04和12.10上使用g++(4.7.2)编译、链接和运行,但在FC17上编译失败并出现此错误。ArchiveServiceLib/debug-posix/libArchiveLib.a(NamedIflTiffCache.o):(.rodata._ZTV26UnlockingGenericFileHandle[_ZTV26UnlockingGenericFileHandle]+0x58):undefinedreferenceto`I

C++ : noexcept (or throw()) virtual destructor = default;

下面的代码是合法的吗?classC{virtual~C()noexcept=default;};或classC{virtual~C()throw()=default;};(throw()已弃用,但我的编译器不支持noexcept;;) 最佳答案 8.4.2[dcl.fct.def.default]Anexplicitly-defaultedfunction[...]mayhaveanexplicitexception-specificationonlyifitiscompatible(15.4)withtheexception-spe

c++ - 警告 : non-static data member initializers only available with -std=c++11 or -std=gnu++11 [enabled by default]

这个问题在这里已经有了答案:C++ArrayInitializersWarnings(2个答案)关闭8年前。我刚刚在我的机器上安装了最新版本的cygwin和eclipseluna。它工作正常,我能够运行我的项目。但是,当我构建它们时,我收到了我不明白的警告。例如,这是我从“c++Primer”一书的网站上获得的头文件“Sales_item.h”的警告:warning:defaultedanddeletedfunctionsonlyavailablewith-std=c++11or-std=gnu++11[enabledbydefault]Sales_item()=default;^..

c++ - "Control reaches end on non-void function"with do { 返回结果; } 而(条件);

我有以下功能(简化示例):QByteArrayDecompressBytes(constQByteArray&content){/*functionbody(withotherreturnexpressions)*/do{returncontent;}while(content.size()!=0);}添加最后一行用于测试,替换使用的宏。VisualStudio没有发现此代码有问题,但g++生成了warning:controlreachesendofnon-voidfunction[-Wreturn-type]将最后一行更改为returncontent;删除警告。我的问题:为什么编译器

c++ - 嵌套类声明 : template vs non-template outer class

我有一个C++模板类,里面有一个嵌套类,比如:templateclassOuter_t{public:classInner;Inneri;};templateclassOuter_t::Inner{public:floatx;};intmain(){Outer_to_t;//3oranyarbitraryinto_t.i.x=1.0;return0;}编译没有任何问题。然而,一旦我声明了一个类似的非模板类,就像这样:classOuter_1{public:classInner;Inneri;};classOuter_1::Inner{public:floatx;};intmain(){

c++ - 通常方法上的 Woverloaded-virtual 警告

我很困惑为什么下面的代码会产生Woverloaded-virtual警告。classTestVirtual{public:TestVirtual();virtualvoidTestMethod(inti);};classDerivedTestVirtual:publicTestVirtual{public:voidTestMethod();};派生类具有不带参数的常用方法TestMethod-签名不同于基类的类似虚拟方法。那为什么编译器不能解决这种情况呢? 最佳答案 警告的原因是无参数版本从基类中隐藏了int版本。DerivedTe

c++推导 "non type pointer to function"类模板参数

考虑一个模板类:templateclassProxy{voidrun(){ReturnTyperet=Fn();//...dosomething...}};//andafunctionsintfn1(){return5;}floatfn2(){return5;}这可以通过使用实例化:Proxyp1;但是显式声明返回值类型似乎是不必要的。我想要实现的是:someProxyInstantationp1;someProxyInstantationp2;不幸的是,我对c++没有任何期望,这似乎是该语言的一个隐藏角落(至少对我而言)。如果我可以从指向函数的指针获取它的类型——类似于:std::t