>>Q: shouldn't void poop() and void pee() return objects ?
It could, but you're voiding yourself of your feces and urine.
>>what exactly is, " this-> "
The keyword 'this' gives a pointer to the object that it's in. For example:
In this example, both ptr1 and ptr2 will contain valid pointers to the Person object called 'p'. I believe that's how cout works; its operator<< () is defined to return an ostream&, so what it does is:
ptr1 = &p;
ptr2 = p.getPointerToTheObject();
1. Output whatever came after the <<
2. Return (*this) (this returns a pointer to itself; so de-reference the pointer and it returns itself).
That's why you can chain together a bunch of <<:
cout << "Hello! My name is " returns cout, so the next step is cout << name, which returns cout, etc. and you get a nice chain reaction type thing going on
((((cout << "Hello! My name is ") << name) << " and I am ") << age) << "years old!";
And to answer your question:
is the same as
So in short, -> is a shortcut that we use because we're lazy. Also, you can overload the -> operator, but that's not done very often so you probably don't need to worry about it. Putting it all together, this->doSomething() is basically saying (this current object).doSomething().