草庐IT

future_base

全部标签

c++ - 同名类之间的共享 vtables : call to virtual method crashes when casting to base type

检查下面的更新,我可以重现并需要帮助。我有一个奇怪的崩溃,其中一些方法在除1个地方之外的任何地方都可以正常工作。这是代码:structbase{virtualwchar_t*get()=0;//canbe{returnNULL;}doesn'tmatter};structderived:publicbase{virtualwchar_t*get(){returnSomeData();}};structcontainer{deriveddata;};//thisisapprox.howitisusedinrealprogramvoidoutput(constbase&data){data

c++ - 错误 : Range-based 'for' loops are not allowed in C++98 mode

所以我正在关注此页面上的教程:http://www.cplusplus.com/doc/tutorial/control/但是我在做范围/基于for循环时遇到了麻烦。我找到了这个页面:GNUGCCcompilerupdating那里的答案说我应该打开“项目”和“属性”。但是当我尝试这样做时,“属性”选项变灰了,没有任何解释:http://imageshack.com/a/img571/4371/xd1x.png那么..我怎样才能激活范围/基于for循环? 最佳答案 将-std=c++11标志传递给编译器。当然,GCC应该足够新(>=

c++ - 将执行从一个线程转移到另一个线程以实现任务并行性和 future 调用

我正尝试在C++中实现一个future调用机制。虽然这只是一个测试代码(制作有点匆忙),但我打算在我正在使用的一种语言的运行时使用类似的东西来实现透明并行。我已经干掉了我正在处理的代码以使其更小一些,尽管它仍然很大:#include#include#include#include#include#include#include#include#include#includeusingnamespacestd;usingnamespacestd::chrono;//--------------------------------------------------------------

C++ 方法重载 : base and derived parameters

在网上搜索后,我没有设法找到这个问题的答案:我有这个重载方法:foo(Base*base);foo(Derived*derived);在这种情况下,“Derived”是“Base”的子类。当我打电话时:foo(newDerived());我注意到总是调用第一个重载方法,而我想获得相反的结果(调用以“Derived*”对象作为参数的方法)。如何解决?谢谢。编辑:好的,这是我的实际情况:我有一个UIWidget和一个UIScoreLabel类。UIScoreLabel派生自UIWidget。我还有一个GameEvent类(Base)和一个P1ScoreGameEvent类(Derived)

c++ - 为什么 'Base Class object' 不能调用它自己的虚函数? C++

我已经阅读了C++中的虚函数,并了解它们如何为程序员提供使用基类指针访问派生类成员函数的权限。(又名多态性)。一直困扰我的问题是:为什么要在基类中声明一个同名函数,如果最后它必须被声明为虚函数?(注意:我需要有关虚函数多态性方面的答案)在下面的代码中,如果使用基类指针调用“virtualdisplay()”(第22行),则会显示错误。为什么C++中的虚函数如此严格w.r.t.没有被基类指针调用?.#includeusingnamespacestd;classB{public:voidvirtualdisplay(){coutdisplay();Whycan't'b'callit'sow

c++ - 为什么friend类可以通过Derived类访问到Base类私有(private)数据

这是我第一次在这里发帖。classBase{private:intbase;friendclassQuestion;};classDerived:publicBase{private:intsuper;};classQuestion{public:voidtest(Base&base,Derived&derived){intvalue1=base.base;//Noproblem,becauseQuestionisafriendclassofbaseintvalue2=derived.super;//Compileerror,becauseQuestionisnotafriendcla

c++ - 意外的 std::io_base::failure 异常

这个问题在这里已经有了答案:Unexpectedexceptioninstd::ifstream(1个回答)关闭7年前。以这个简单的程序为例:#includeintmain(){std::ifstreamin(".");intx;if(in)in>>x;}在Redhat6、gcc4.4.7上运行没有错误在Ubuntu14.04LTS上,gcc4.8.2运行没有错误在Redhat7上,gcc4.8.2我得到:terminatecalledafterthrowinganinstanceof'std::ios_base::failure'what():basic_filebuf::under

c++ - Boost::Future 延迟延续展开死锁

我正在使用Boost的promise和future并在使用延续时遇到了边缘情况。我的代码使用一个返回future的延续,并在获取其值之前解包then()的结果。#defineBOOST_THREAD_VERSION5#include#includeintmain(intargc,char*argv[]){boost::promisepromise;boost::futurefuture=promise.get_future();promise.set_value(42);intresult=future.then(boost::launch::async,[](boost::futur

c++ - 从C++模板特化那 "base"调用 "overrides"模板函数呢?

问题:有没有一种方法可以从C++中的专用模板函数调用“基本”模板函数,子类可以在覆盖它们时访问父类的虚拟方法版本?(注意:我怀疑答案是“否”,但很想是错误的)上下文:我经常发现自己专门化模板函数只是因为特殊情况需要额外的预处理或后处理,而不是因为代码的“内脏”发生了变化。举个例子:通过继承,您可以执行以下操作:structbase{virtualvoidgo(){printf("%p",this);}};structfoo:base{virtualvoidgo(){printf("thisfoolivesat");base::go();}};...调用foo::go()将打印“this

c++ - std::promise 是否在内部使用 std::condition_variable 来通知关联的 std::future?

我的问题是std::promise是否通过使用std::condition_variable通知关联的std::future?我搜索了std::promise的源代码并找到了这个website.但是我没有看到std::promise在其成员数据中有std::condition_variable。 最佳答案 这是libc++的答案。搜索condition_variable在只返回一个结果://lines531--538class_LIBCPP_TYPE_VIS_LIBCPP_AVAILABILITY_FUTURE__assoc_sub