I was doing some reading on the 'this' pointer, and I think I understand it more than I originally did, but I still need some clarification. So, by my understanding, if you have
class Simple
{
private:
int m_nID;
public:
Simple(int nID)
{
SetID(nID);
}
void SetID(int nID) { m_nID = nID; }
int GetID() { return m_nID; }
};
The SetID(int nID) function actually is semantically converted into:
void SetID(Simple* const this, int nID) { this->m_nID = nID; }
It makes sense that, there is a this pointer for all member functions of a class, for the most part. But what happens if you have a member function that takes no arguments? Is there a 'this' pointer? If so, does it point to the return type instead of the argument type?
But what happens if you have a member function that takes no arguments? Is there a 'this' pointer? If so, does it point to the return type instead of the argument type?
Even your method do not have any argument, it still have one hidden parameter, that is this pointer.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With