Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我无法访问以下 C++ 代码中的 class'es 字段:
class Human { string address; public: void setAddress( string address ) { this.address = address; } };
此代码将导致错误“错误 C2228:'.address' 左侧必须具有类/结构/联合”。正确的做法是什么?
this是指向您当前实例的指针,因此您应该使用->而不是点。
this
->
class Human { string m_address; public: void setAddress( string address ) { m_address = address; } };
与 JavaScript 不同,您不需要使用“this”。这里通常给函数参数一个不同的名称以避免歧义