code_junkie

Why can't we use “this” inside the class

Nov 13th, 2011
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.20 KB | None | 0 0
  1. class Test {
  2. public:
  3. void setVal(const std::string& str) {
  4. this.isVal = str; //This will error out
  5. }
  6.  
  7. private:
  8.  
  9. string isVal;
  10. };
  11.  
  12. (*this).isVal = str;
  13.  
  14. isVal = str;
Add Comment
Please, Sign In to add comment