The easiest way is to think of this as a hidden optional argument, which is always passed automatically.
So, a fictional method like:
size_t String::length(void) const { return strlen(m_string); }
actually more like a hood:
size_t String__length(const String *this) { return strlen(this->m_string); }
and a call like:
{ String example("hello"); cout << example.length(); }
becomes something like:
cout << String__length(&example);
Please note that the above conversion is simplified, we hope that my point will become more clear. No need to fill in the comments "whaaa, where is the sort to overload the method, right?" - like objections, please. :)
This turns the question into βwhere are the arguments stored?β And the answer, of course, βdoes it depend.β :)
This is often on the stack, but it can also be in registers, or any other mechanism that the compiler considers useful for the target architecture.
unwind May 16 '13 at 10:56 2013-05-16 10:56
source share