我有这段代码:
Wmmbid02 wmmbid02;
wmmbid02.Omplir(this);
return wmmbid02;
和 Wmmbid02.h:
class Wmmbid02: public Idoc {
public:
Wmmbid02();
//void EscriureFitxer();
void Omplir(Edi);
private:
Segment crearSegment(string a[], string b[]);
Info crearInfo(string);
//virtual void LlegirFormat(string);
};
Visual Studio,返回错误,因为无法将“Edi *const”转换为“Edi”。
正确答案是什么???
谢谢
最佳答案
您的 Omplir
声明
void Omplir(Edi);
表示此方法接受一个 Edi
对象。
在 C++ 中,this
是一个指针。您应该在类中使用它。
如果你想让它工作,你应该取消引用它:
wmmbid02.Omplir(*this);
关于this
指针的标准是这样说的:
9.3.2 The this pointer [class.this]
In the body of a non-static (9.3) member function, the keyword this is a prvalue expression whose value is the address of the object for which the function is called. The type of this in a member function of a class X is X*. If the member function is declared const, the type of this is const X*, [...]
所以在你的情况下,你似乎在类 Edi
的成员函数中,this
应该是 Edi*
类型.
关于C++ 对象引用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18868004/