fork download
  1. #include<iostream>
  2. using namespace std;
  3. class Test
  4. {
  5. private:
  6. int x;
  7. public:
  8. Test(int x = 0) { this->x = x; }
  9. void change(Test *t) { this = t; }
  10. void print() { cout << "x = " << x << endl; }
  11. };
  12. int main()
  13. {
  14. Test obj(5);
  15. Test *ptr = new Test (10);
  16. obj.change(ptr);
  17. obj.print();
  18. return 0;
  19. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp: In member function ‘void Test::change(Test*)’:
prog.cpp:9:33: error: lvalue required as left operand of assignment
   void change(Test *t) { this = t; }
                                 ^
stdout
Standard output is empty