抱歉,如果这是一个微不足道的问题:
实现 1:
class Foo
{
protected: int bar;
public: Foo(int bar)
{
this->bar =bar;
}
};
实现 2:
class Foo
{
protected: int bar;
public: Foo(int bar)
{
this.bar =bar;
}
};
实现 2 的输出:
请求“this”中的成员“x”,其指针类型为“Foo* const”(也许您打算使用“->”?)
所以 this
是一个指针,并且 this问题在代码中有语法错误
最佳答案
您所指的问题包含用 C# 而不是 C++ 编写的代码示例。是的,在 C++ 中,this
是一个指针,必须取消引用才能访问它指向的对象的任何成员。
关于c++ - 澄清 `this` 关键字,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13767394/