Who can tell more about the pointer this->. Here is a small piece of code:
#include <iostream> class thisis{ private: int var; public: thisis(int var) { this->var = var; std::cout << var; }; void getit() { std::cout << var; }; }; int main(){ thisis obj1(2); obj1.getit(); return 0; }
Okay nothing complicated, the most common example from the book, we just made the assignment. which is equivalent to the usual assignment (only with one but, we have two variables of the same name and therefore we needed to rename one of them). just a pointer that works in a class. but the meaning of this pointer, maybe it has another use?
this
practically not needed; Member initializer is more convenient:thisis(var): var(var) { std::cout << var; }
thisis(var): var(var) { std::cout << var; }
. The only known application to me is in assignment operators:return *this;
- user58697не
instead ofмне
- user58697