Jump to content
  • Advertisement
Sign in to follow this  

Simple Little Question

This topic is 4386 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, In a C++ object member, will my code run slower if I use the 'this' pointer? It seems like a more readable construction, but is there a cost? Cheers, Graham
if (this->Id) {
// Do something
}

//versus

if (Id) {
// Do something
}

Share this post


Link to post
Share on other sites
Advertisement
No, using this can clear ambiguities for the compiler but will not make a difference in terms of performance.

Plus another thing - if you want members to be seen clearly, you might want to use the well-accepted "m_" prefix as a convention. In your case you would use m_Id as the name of the member.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
the "this" pointer is implicit for member variables, so no need and no runtime gain by (not) using it.

Share this post


Link to post
Share on other sites
As an aside, I really, really don't understand why anyone finds it "more readable" to type the this->. I personally only use it when needed for disambiguation. As long as you're thinking in terms of writing the member function "from the object's perspective", it really doesn't add any useful information.

Share this post


Link to post
Share on other sites
Quote:
Original post by Zahlman
As an aside, I really, really don't understand why anyone finds it "more readable" to type the this->. I personally only use it when needed for disambiguation. As long as you're thinking in terms of writing the member function "from the object's perspective", it really doesn't add any useful information.


It isn't more readable; but it seems to help MSVC's Intellisense, esp. inside templates.

I prefer not to use "this->", personally.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!