草庐IT

this_call

全部标签

c++ - 'this' cannot be used in a constant expression error (C++)

全部。我有一个定义如下的类:classBoard{intcolumns,rows;boolboard[10][10];public:Board(int,int);voidnextFrame();voidprintFrame();};我的voidnextFrame()一直给我[rows][columns]的错误,因为对于它们两者来说“'this'不能在常量表达式中”。我怎样才能重新定义它以使其起作用?我明白这个错误。函数的定义如下,错误发生在以下代码示例的第3行。voidBoard::nextFrame(){intnumSurrounding=0;booltempBoard[rows][

c++ - 构造函数中的 weak_from_this()

我知道您不能在构造函数中使用shared_from_this。但是可以在构造函数中使用新的weak_from_this吗?根据cppreference:Thisisacopyofthetheprivatemutableweak_ptrmemberthatispartofenable_shared_from_this.http://en.cppreference.com/w/cpp/memory/enable_shared_from_this/weak_from_this我没有看到从构造函数中获取内部存储的weak_ptr拷贝的问题,但我可能遗漏了一些东西,所以我不确定这一点。

c++ - COM 互操作 : how to use ICustomMarshaler to call 3rd party component

我想使用COM互操作从C#调用COM组件中的方法。这是方法签名:longGetPrecursorInfoFromScanNum(longnScanNumber,LPVARIANTpvarPrecursorInfos,LPLONGpnArraySize)这是在C++中调用它的示例代码(我检查过它确实有效):structPrecursorInfo{doubledIsolationMass;doubledMonoIsoMass;longnChargeState;longnScanNumber;};voidCTestOCXDlg::OnOpenParentScansOcx(){VARIANTv

c++ - 没有过剩的 OpenGL 渲染球体 : What is wrong with this implementation?

在我的渲染循环中,我有以下逻辑。我还有其他东西渲染到屏幕上,它们也渲染了(我删除了该代码以切中要点)。这段代码不渲染球体,我不明白为什么不。我在数学上遗漏了什么吗?我已经逐步调试了调试器,值似乎是正确的。注意mBubbleDiameter在此对象的构造函数中设置为20。staticGLfloatstaticDegreesToRadians(GLfloattmpDegrees){returntmpDegrees*((std::atan(1.0f)*4)/180.0f);}voidLedPannelWidget::updateGL(){glMatrixMode(GL_PROJECTION)

c++ - 重载和 this 指针

这个问题更像是理论问题。前言。访客模式:classVisitor{public:virtualvoidVisitElementA(constElementA&obj)=0;virtualvoidVisitElementB(constElementB&obj)=0;};classElement{public:virtualvoidAccept(Visitor&visitor)=0;};classElementA:publicElement{public:voidAccept(Visitor&visitor)override{visitor.VisitElementA(*this);}};

c++ - 无法重载对 *this 的引用

这是我为N2439(“this”的引用限定符)使用gcc-4.8.1+中的新功能(我认为clang-2.9+也应该这样做)编写的一个busybox:classFoo{public:Foo(inti):_M_i(i){}intbar()&{return_M_i/=2;}intbar()const&{return_M_i;}intbar()&&{return2*_M_i;}private:int_M_i=42;};intmain(){Fooph(333);ph.bar();constFooff(123);ff.bar();Foo(333).bar();}在阅读标准8.3.5时,我认为三个b

c++ - 存储右值引用 : should this work?

我正在通过故意破坏事物来测试我对左值和右值引用的理解。所以说有这个结构:structFooBar{FooBar(int&&number):rNumber(number){}int&rNumber;};然后我创建了一个实例FooBarobj(5)。每次尝试读取引用变量都会返回正确的结果(5)。如果我使用constint&而不是int&&,也会发生同样的情况。我注意到将int替换为std::string并读取引用会返回一个空字符串,因此我怀疑它给出了未定义的行为。是这样吗?如果是这样,为什么它适用于整数?更新:我正在创建实例并像这样读取它:FooBarobj(5);//FooBarobj(

c++ - 为什么这在 C++ 中抛出 "CryptoMaterial: this object contains invalid values",但在 python 中工作正常

我正在与Mega.co.nz的API交互,使用python库作为引用,并且此代码正在抛出。私钥属于临时账户。当我只使用第一个素数时它可以工作,但如果我包含第二个素数它会抛出,但在python代码中一切正常。此代码抛出“CryptoMaterial:此对象包含无效值”//g++test.cpp-otest-lcryptopp#include#include#include#includeusingnamespaceCryptoPP;constIntegerc("1085716632638270376006277952876684336882093057659821322727847155

c++ - 获取函数的地址并在编译时丢弃它 : is this valid C++?

我一直在寻找一种方法来将模板类型参数限制为那些实现给定签名功能的参数。我似乎已经找到了一个非常优雅的解决方案,它允许self记录代码和相当干净的、类似于概念的错误消息。唯一的问题是我不确定那是有效的C++还是恰好在clang和gcc中工作的东西。代码如下:#includeusingstd::enable_if;//let'ssaywewantsomethingwitha"regular"operator+classThing{public:Thingoperator+(constThing&){returnThing();}//thekindofoperatorwewant};clas

C++:通用 "call-functions-f-followed-by-g"方法?

是否有可能有一个通用方法接受两个函数f和g(都返回void并接受参数相同类型)并返回一个新函数,该函数接受与f和g相同类型的参数,并首先将f应用于传递的参数和然后g?具体来说,我想定义这样的东西:template//FunctionTypeisvoid(ArgType1arg1,ArgType2arg2,..)FunctionTypeCombineTwoFunctions(FunctionTypef,FunctionTypeg){//Usingthelambdasyntaxjustforillustration:return[f,g](ArgsOf(FunctionType)args)