943,590 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 1420
  • C++ RSS
Feb 21st, 2009
0

this pointer

Expand Post »
Hello guys,
I'm very green in c++ and just started to understand classes and objects. I'm reading on the web about this pointer, but having difficulties understanding how it works exactly, could aanybody please help me understand or reference a good article for total noobs in c++ to grasp the this concept in simple explanation? would be greatly appreciated.

thank you

andre
Similar Threads
Reputation Points: 10
Solved Threads: 0
Junior Poster in Training
atman is offline Offline
50 posts
since Oct 2008
Feb 21st, 2009
0

Re: this pointer

Reputation Points: 1234
Solved Threads: 347
Postaholic
ArkM is offline Offline
2,001 posts
since Jul 2008
Feb 21st, 2009
0

Re: this pointer

I rarely need to use it. If you are within the scope of the class, MyVariable is the same as this->MyVariable. It is sometimes just nice for other people that read your code so that they know where these variables reside.

Dave
Featured Poster
Reputation Points: 437
Solved Threads: 204
Posting Virtuoso
daviddoria is offline Offline
1,968 posts
since Feb 2008
Feb 21st, 2009
0

Re: this pointer

I agree that I generally don't use the this pointer.
About the only time I use it is when I call a method or function outside of the class that needs to refer back to my object.
An example might be registering my object with a 'server object' for callbacks.
Reputation Points: 344
Solved Threads: 116
Practically a Master Poster
Murtan is offline Offline
670 posts
since May 2008
Feb 21st, 2009
0

Re: this pointer

Look body, the pointer is a main axis in C Language -the person who understand these pointer is the person who is well understanding the programming concepts. Get Data Structure Books which takes its steps in the pointer way -Stacks, queues, lists, and tree in the array implementation and the linked one.
That what I have!
Good Luck...
Reputation Points: 7
Solved Threads: 0
Newbie Poster
Mostafa Adel is offline Offline
5 posts
since Feb 2009
Feb 22nd, 2009
0

Re: this pointer

>... the person who understand these pointer is the person who is well understanding the programming concepts.
Read a sentence backwards - that's right ..
Reputation Points: 1234
Solved Threads: 347
Postaholic
ArkM is offline Offline
2,001 posts
since Jul 2008
Feb 22nd, 2009
0

Re: this pointer

this pointer has its own use:
first of all if you are dealing in a big project, you may use the convention this-member to differentiate between the member of the same global identifiers.
Moreover, it increases the readability of the code.
Secondly, you may like to use it if u do operator overloading for your class, like when you are overloading the assignment operator, you could return the this pointer itself.

But then, it is a fact that pointer do mess things up. moreover, C++ STL provide you with all those things you will hardly need to know about pointers.
This is what encapsulation is. And thats why OOP rocks.

But then, understanding pointers have its own merits. So I prefer that you should probably read about it surely.
Reputation Points: 1486
Solved Threads: 140
Practically a Posting Shark
siddhant3s is offline Offline
816 posts
since Oct 2007

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: program with padding a string.
Next Thread in C++ Forum Timeline: PRIME number in an array





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC