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

Recommended Answers

All 6 Replies

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

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.

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...

>... the person who understand these pointer is the person who is well understanding the programming concepts.
Read a sentence backwards - that's right ;)..

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.