草庐IT

init_from_stream

全部标签

c++ - 这个技巧是否会使在构造函数 'just work' 中调用 shared_from_this() 变得危险?

C++专家的问题。我们都知道在类构造函数中调用shared_from_this()会导致bad_weak_ptr异常,因为尚未创建实例的shared_ptr。为了解决这个问题,我想到了这个技巧:classMyClass:publicstd::enable_shared_from_this{public:MyClass(){}MyClass(constMyClass&parent){//Createatemporarysharedpointerwithanull-deleter//topreventtheinstancefrombeingdestroyedwhenit//goesouto

c++ - 错误 C2440 : 'initializing' : cannot convert from 'initializer-list'

#includeusingnamespacestd;structTDate{intday,month,year;voidReadfromkb(){cout>day>>month>>year;}voidprint(){cout为什么我收到错误1​​errorC2440:'initializing':cannotconvertfrom'initializer-list'to'TDate'and2IntelliSense:toomanyinitializervalues。当我删除boolvalid和intID时,程序可以运行。为什么会这样? 最佳答案

c++ - OSG : Get transform matrix from a node

首先,我必须为我的英语道歉。我正在开发一个应用程序,我们必须在每个时刻知道每个节点的属性(位置、旋转...),所以我考虑从场景图中获取每个节点的变换矩阵。我遇到的问题是我不知道该怎么做。例如,如果我有这样的东西:osg::ref_ptrroot=osgDB::readNodeFile("cessna.osg.15,20,25.trans.180,90,360.rot.2,3,4.scale");我想从名为root的Node对象中获取变换矩阵。我发现了类似的东西:osg::Matrixmat=osg::computeWorldToLocal(this->getNodePath());st

c++ - Qt 信号/槽 : Is it an error to emit a signal from a temporary object?

在Qt中,如果从一个临时对象中调用一个信号,使得该对象可能在调用槽时被删除,这是一个错误吗?如果相关,代码会从临时对象的构造函数发出信号。(注意:没有指针或引用作为参数传递,所以这不是关于悬挂指针或引用的问题。我只是想知道,以最简单的形式,从Qt中的一个临时对象。)这是我的代码的简化版本://MyapplicationclassHandyApplication:publicQApplication{Q_OBJECTpublic:explicitHandyApplication(intargc,char*argv[]);signals:publicslots:voidhandySlot(

c++ - SIMD 内部函数 : _mm_stream_load_si128 vs _mm_load_si128

什么时候应该使用流媒体版本以及什么时候使用SSE2与_mm_load_si128?什么是性能权衡? 最佳答案 流加载内在(mm_stream_load_si128)执行加载“使用非时间内存提示”(根据IntelIntrinsicsGuide)。这意味着加载的值不会导致从缓存中逐出任何内容。如果您将大量数据组合在一起,您将立即对其进行操作并且“很长”一段时间内不再查看,这将非常有用。最常见的情况是在流操作期间发生这种情况。当我知道我正在对一个大数据集执行一个简单的操作时,我就使用过它,我知道数据无论如何都会很快从缓存中被逐出。memc

c++ - 不合格的名称查找 : Why local declaration hides declaration from using directive

考虑这段代码:namespaceA{inti=24;}namespaceB{usingnamespaceA;inti=11;intk=i;//findsB::i,noambiguity}和basic.lookup.unqual.2:§6.4.1Unqualifiednamelookup[basic.lookup.unqual]Thedeclarationsfromthenamespacenominatedbyausing-directivebecomevisibleinanamespaceenclosingtheusing-directive;see[namespace.udir].F

c++ - 在 init 方法中绕过 const

所以我can'tuseinitializersinmyclassconstructor因为使用数组,所以我决定改用init()方法。现在我有一个不同的问题。我有这样一个类:classEPWM{private:volatileEPWM_REGS*constregs;public:voidinit(volatileEPWM_REGS*_regs);};我需要通过初始化regs=_regs;来实现init()但我不能因为const。有没有办法在我的init方法中强制分配?我想保留const关键字,这样我就不会不小心重新分配到别处。编辑:尽管我很想使用构造函数+初始值设定项来解决这个问题(我的

c++ - 错误 : invalid conversion from 'void (*)()' to 'void (*)()' -- what?

我正在尝试将回调函数从C++传递到OpenGL(CAPI):gluQuadricCallback(qobj,GLU_ERROR,errorCallback);其中errorCallback是编译为C++代码的文件中的函数,声明为voiderrorCallback();代码在Linux上使用g++4.4编译干净,但在Windows上使用mingw32g++4.4时出现以下错误:..\glwidget.cpp:172:error:invalidconversionfrom'void(*)()'to'void(*)()'..\glwidget.cpp:172:error:initializi

c++ - 如何在 emacs C++ 编译模式下跳过 "in file included from"?

我喜欢使用emacs编译我的C++项目,使用编译模式和next-error跳转到源代码中的警告和错误。但是,我发现非常烦人的是next-error将我带到编译输出中的每个#include行“Infileincludedfrom”。我知道您可以使用compilation-skip-threshold跳过警告,但我不想跳过警告,这些包含行显示为警告。对我来说这似乎是编译模式中的错误(这些不是警告),但是thisbug被关闭为“不是错误”具体来说,对于如下所示的输出:Infileincludedfrom/path/to/file1.h:linenum1:Infileincludedfrom/

解决git报错 “remote: Please remove the file from history and try again.”

使用git提交代码时报错:remote:error:File:90b39f4470e405ed852e517a73473b527ac60eaa362.16MB,exceeds100.00MB.remote:Usecommandbelowtoseethefilename:remote:gitrev-list--objects--all|grep90b39f4470e405ed852e517a73473b527ac60eaaremote:Pleaseremovethefilefromhistoryandtryagain.应该是提交的文件中有超过100MB的。解决方案:1、按照提示执行命令查看超大的