How can you assign a value to the pointer 'this' in C++

后端 未结 6 2166
北荒
北荒 2020-12-08 21:03

In a function, how to you assign this a new value?

6条回答
  •  一生所求
    2020-12-08 21:41

    You can not. "this" is a hidden argument to every member function of a class and its type for an object of Class X is X* const. This clearly means that you can not assign a new vale to "this" as it is defined as a const. You can however modify the value pointed to by this. Refer http://www.geeksforgeeks.org/this-pointer-in-c/ for more details.

提交回复
热议问题