[英]C++ Call Member Function Within An Object of an Object
I have a C++ class which, in short, has a declaration which looks like this: 我有一个C ++类,简而言之,有一个看起来像这样的声明:
class Pico {
...
Document document; // Custom Document class
...
}
Later I call one of the public member functions of the Document
class: 稍后,我调用
Document
类的公共成员函数之一:
this->document->enableEditing();
However, IntelliSense underlines this
and notes that "expression must have pointer type". 但是,IntelliSense强调了
this
并指出“表达式必须具有指针类型”。 What can I do to fix this? 我该怎么做才能解决此问题?
You want 你要
this->document.enableEditing();
The Document
member is not a pointer, therefore you need .
Document
成员不是指针,因此需要.
in place of ->
代替
->
document
is not a pointer, so you do not need the ->
operator: document
不是指针,因此不需要->
运算符:
this->document.enableEditing();
In fact, in this case it isn't even necessary to use this
explicitly. 实际上,在这种情况下,甚至没有必要显式使用
this
。 The following will do: 将执行以下操作:
document.enableEditing();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.