this pointer

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Oct 2008
Posts: 48
Reputation: atman is an unknown quantity at this point 
Solved Threads: 0
atman atman is offline Offline
Light Poster

this pointer

 
0
  #1
Feb 21st, 2009
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
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 2,001
Reputation: ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of 
Solved Threads: 343
ArkM's Avatar
ArkM ArkM is offline Offline
Postaholic

Re: this pointer

 
0
  #2
Feb 21st, 2009
Reply With Quote Quick reply to this message  
Join Date: Feb 2008
Posts: 638
Reputation: daviddoria is a jewel in the rough daviddoria is a jewel in the rough daviddoria is a jewel in the rough 
Solved Threads: 46
daviddoria daviddoria is offline Offline
Practically a Master Poster

Re: this pointer

 
0
  #3
Feb 21st, 2009
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
Reply With Quote Quick reply to this message  
Join Date: May 2008
Posts: 631
Reputation: Murtan is a jewel in the rough Murtan is a jewel in the rough Murtan is a jewel in the rough Murtan is a jewel in the rough 
Solved Threads: 102
Murtan Murtan is offline Offline
Practically a Master Poster

Re: this pointer

 
0
  #4
Feb 21st, 2009
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.
Reply With Quote Quick reply to this message  
Join Date: Feb 2009
Posts: 5
Reputation: Mostafa Adel is an unknown quantity at this point 
Solved Threads: 0
Mostafa Adel's Avatar
Mostafa Adel Mostafa Adel is offline Offline
Newbie Poster

Re: this pointer

 
0
  #5
Feb 21st, 2009
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...
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 2,001
Reputation: ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of 
Solved Threads: 343
ArkM's Avatar
ArkM ArkM is offline Offline
Postaholic

Re: this pointer

 
0
  #6
Feb 22nd, 2009
>... the person who understand these pointer is the person who is well understanding the programming concepts.
Read a sentence backwards - that's right ..
Reply With Quote Quick reply to this message  
Join Date: Oct 2007
Posts: 794
Reputation: siddhant3s has much to be proud of siddhant3s has much to be proud of siddhant3s has much to be proud of siddhant3s has much to be proud of siddhant3s has much to be proud of siddhant3s has much to be proud of siddhant3s has much to be proud of siddhant3s has much to be proud of siddhant3s has much to be proud of siddhant3s has much to be proud of 
Solved Threads: 135
siddhant3s's Avatar
siddhant3s siddhant3s is offline Offline
Master Poster

Re: this pointer

 
0
  #7
Feb 22nd, 2009
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.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



Tag cloud for C++
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC