- #1
yungman
- 5,755
- 292
I have been reading this pointer. I read this article: https://www.geeksforgeeks.org/this-pointer-in-c/
" Meaning each object gets its own copy of data members and all objects share a single copy of member functions. "
Is this true? I just want to make sure that there is really only ONE COPY of the member functions in the memory for each class and ALL objects share the same set of functions.
Also another article https://docs.microsoft.com/en-us/cpp/cpp/this-pointer?view=msvc-160
claims "{month = mn; this->month = mn; (*this).month = mn;} // These three statements are equivalent". why do I need the "this" pointer? It's almost like putting "this" just to make it more confuse! Just use month = mn.
Seems like a lot of the stuffs in operator overloading are more for "elegance" than really necessary. You can easily write a few more lines instead of using all these "elegant" code just to save a few lines. Problem is people are using this, you won't be able to follow their codes without understand it.
Thanks
" Meaning each object gets its own copy of data members and all objects share a single copy of member functions. "
Is this true? I just want to make sure that there is really only ONE COPY of the member functions in the memory for each class and ALL objects share the same set of functions.
Also another article https://docs.microsoft.com/en-us/cpp/cpp/this-pointer?view=msvc-160
claims "{month = mn; this->month = mn; (*this).month = mn;} // These three statements are equivalent". why do I need the "this" pointer? It's almost like putting "this" just to make it more confuse! Just use month = mn.
Seems like a lot of the stuffs in operator overloading are more for "elegance" than really necessary. You can easily write a few more lines instead of using all these "elegant" code just to save a few lines. Problem is people are using this, you won't be able to follow their codes without understand it.
Thanks