I understand what this does, but what is the difference between *this and this?
Yes, I have Googled and read over *this in my text book, but I just don’t get it…
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
thisis a pointer, and*thisis a dereferenced pointer.If you had a function that returned
this, it would be a pointer to the current object, while a function that returned*thiswould be a “clone” of the current object, allocated on the stack — unless you have specified the return type of the method to return a reference.A simple program that shows the difference between operating on copies and references:
Output:
You can see that when we operate on a copy of our local object, the changes don’t persist (because it’s a different object entirely), but operating on a reference or pointer does persist the changes.