例如
class Test {
public:
void setVal(const std::string& str) {
this.isVal = str; //This will error out
}
private:
string isVal;
};
Run Code Online (Sandbox Code Playgroud)
Fry*_*Guy 15
除了克里斯的回答,您还可以:
(*this).isVal = str;
Run Code Online (Sandbox Code Playgroud)
然而,做克里斯所说的更好,因为它更正统.这只是说明在调用指针之前需要取消引用指针.