草庐IT

non-virtual

全部标签

c++ - 线程错误 : invalid use of non-static member function

这个问题在这里已经有了答案:Passingmemberfunctionstostd::thread[duplicate](2个答案)关闭5年前。我想了解C++中的线程,但我不知道如何解决这个问题。我想调用两个线程来运行名为“createS”的函数,但出现此错误:error:invaliduseofnon-staticmemberfunction我读过关于这个主题的其他问题,但我真的不明白如何让我的代码工作。有人可以向我解释我做错了什么并尝试帮助我找到解决方案吗?test_class.cppvoidtest_class::generateS(){map1=newmultimap>;map

c++ - 我想我已经重写了一个虚拟方法,但我仍然得到 : "X must implement the inherited pure virtual method Y"

我正在尝试用C++为我正在编写的游戏实现一个接口(interface),但我运行时出错。这是我创建的接口(interface)及其子类://Attack.h//definesasetofvaluesassociatedwithallattacks//andaninterfaceforallattackstypedefunsignedconstintattack_type;typedefunsignedconstintp_attack_type;//definestheattacktypesstaticconstattack_typeNORMAL=0;staticconstattack_

C++ 继承 : Calling virtual method when it has been overridden

我正在尝试构建一个可以在单独的线程中运行(即执行它的run()函数)的service对象。这是服务对象#include#include#include#includeclassservice:publicboost::noncopyable{public:service():stop_(false),started_(false){}virtual~service(){stop();if(thread_.joinable()){thread_.join();}}virtualvoidstop(){stop_=true;}virtualvoidstart(){if(started_.lo

c++ - 当 "virtual"位于 "class Foo : public virtual Bar"而不是 "virtual void frob()"时,这意味着什么?

我在成员函数的上下文中理解virtual,例如virtualvoidfrob()。但它在类声明的上下文中意味着什么,例如classFoo:publicvirtualBar?对于给定的方法,有8种情况源于以下三个位置是否存在virtual:1)父类(superclass)的函数;2)这个类的继承链;3)该类的功能。我想我理解1)和3)是如何相互作用的,但是2)似乎是多余的。是吗?我有什么不明白的? 最佳答案 那是virtualinheritance,当你知道你将进行多重继承时,你就会这样做。该页面有更多详细信息。

c++ - 将私有(private)部分保留在 c++ header 之外 : pure virtual base class vs pimpl

我最近从Java和Ruby切换回C++,令我惊讶的是,当我更改私有(private)方法的方法签名时,我不得不重新编译使用公共(public)接口(interface)的文件,因为私有(private)部分也在.h中文件。我很快想出了一个解决方案,我想这对Java程序员来说是典型的:接口(interface)(=纯虚拟基类)。例如:香蕉树.h:classBanana;classBananaTree{public:virtualBanana*getBanana(std::stringconst&name)=0;staticBananaTree*create(std::stringcons

C++ virtual = 0; 之间的区别和空函数

我现在正在学习C++,OO方面,我一直看到这个:classSomeClass{virtualvoidaMethod()=0;}classAnotherClass{voidanotherMethod(){/*Empty*/}}classSomeClassSon:publicSomeClass{voidaMethod(){/*AlsoEmpty*/}}这3种方法有什么区别?虚等于零,空一,虚,既然继承,空一。为什么我不能让SomeClassSon方法像父亲一样,virtualvoid等于零? 最佳答案 为了你的classSomeClas

c++ - (Re)Using std::algorithms with non-standard containers

我有一个“列”容器类型:structMyColumnType{//Data:Eachrowrepresentsamemberofanobject.vectora;//Allvectorsareguaranteedtohavealwaysvectorb;//thesamelength.vectorc;voidcopy(intfrom_pos,intto_pos);//Thecolumntypeprovidesaninterfacevoidswap(intpos_a,intpos_b);//forcopying,swapping,...voidpush_back();//Andforres

c++ - MSVC : modifiers not allowed on non-memberfunction

我在linux下编写了一个信号/插槽库(Codeprojectarticlehere),同时使用Clang3.5和GCC4.9进行编译。它在两个编译器上编译时都没有警告(也在3.4版和4.8版上)。当我完成所有工作并将文章发布到网上时,没过多久我就收到投诉说它不能在MSVC上工作。(VisualStudioExpress2013?对不起,我对版本控制系统不熟悉。)我把它安装在虚拟机中自己看了一下,发现它不会编译以下内容:templatestructRemoveCV;templatestructRemoveCV{usingType=R(Args...);};templatestructR

c++ - libc++ 与 VC++ : Can non-UTF conversions be done with wstring_convert?

C++11的std::wstring_convert效果很好*用于标准UTF-8UTF-16/UCS2/UCS4转换。但是,当我尝试使用不是来自的构面实例化wstring_convert或wbuffer_convert时,它没有按预期工作://worksasexpectedstd::wstring_convert>ucs4conv;//Now,byanalogy,Iwanttotrythis:std::wstring_convert>gbconv(newstd::codecvt_byname("zh_CN.gb18030"));Clang++错误提示“在~wstring_convert

c++ - 隐式转换 : const reference vs non-const reference vs non-reference

考虑这段代码,structA{};structB{B(constA&){}};voidf(B){cout这compilesfine,运行良好。但是,如果我将f(B)更改为f(B&),它doesn'tcompile.如果我写f(constB&),它又是compilesfine,运行良好。原因和道理是什么?总结:voidf(B);//okayvoidf(B&);//errorvoidf(constB&);//okay对于每种情况,我想听听语言规范中的原因、基本原理和引用资料。当然,函数签名本身并没有错。A隐式转换为B和constB&,但不会转换为B&,这会导致编译错误。