E,g
class Test {
public:
void setVal(const std::string& str) {
this.isVal = str; //This will error out
}
private:
string isVal;
};
E,g
class Test {
public:
void setVal(const std::string& str) {
this.isVal = str; //This will error out
}
private:
string isVal;
};
In C++, this
is a pointer (as opposed to a reference). So you have to say this->isVal
instead.
Adding to Chris's answer, you can also do:
(*this).isVal = str;
However, it's better to do what Chris said, as it is more orthodox. This is just illustrating that you need to de-reference the pointer before calling methods on it.
You also don't really need to use this
explicitly to access member variables/methods. You can simply say:
isVal = str;