0

this, that, these, and those?! THIS is how much THIS makes sense to me. Please help...again.

this.name=name Okay, that's confusing enough. But to then do a changeName and follow it with another this.name=name I really don't get it. I thought, since name already equaled this.name, why do you need to declare it again? I mean, it's not like this.name=red and then it changed to blue! This.name=name in both instances! What The Flip-Flop is going on? I know I have asked for help a lot of times but I really REEAALLYY need help. (So much so that I just broke 2 ethics and etiquette laws!)

5th Oct 2017, 2:07 PM
Michael
Michael - avatar
2 Respuestas
+ 2
In this case the second name usually is a variable, so you are assigning to the property object names the name which you are passing by a variable. If you share code maybe you can have more clear that knowledge
5th Oct 2017, 2:37 PM
Daniel
Daniel - avatar
+ 1
Maybe at lesson Overloading operator for C++ you can learn more, like that code #include <iostream> using namespace std; class MyClass { public: int var; MyClass() { } MyClass(int a) : var(a) { } MyClass operator+(MyClass &obj) { MyClass res; res.var= this->var+obj.var; return res; } }; int main() { MyClass obj1(12), obj2(55); MyClass res = obj1+obj2; cout << res.var; }
5th Oct 2017, 10:10 PM
Daniel
Daniel - avatar