Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8930357
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T08:52:37+00:00 2026-06-15T08:52:37+00:00

I have seen recommended that member functions refer to member variables using this-> explicitly,

  • 0

I have seen recommended that member functions refer to member variables using this-> explicitly, to avoid forgetting to declare the member variable and accidentally referring to a global variable. Can anyone comment if they think this is a reasonable precaution or unnecessary verbosity that will needlessly complicate the reading of the code? Does anybody actually do this in day-to-day real-life programming?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T08:52:38+00:00Added an answer on June 15, 2026 at 8:52 am

    Since I’m frequently implementing class templates, I’m used to always qualify member variables and member functions with this->. In the context of class templates there is another reason why it is useful to qualify names with this->: Names not depending on template arguments are looked up only in phase I look-up, i.e., names in base classes depending on template arguments are never looked up in the base. By qualifying member names with this-> they become dependent. For example:

    #include <iostream>
    
    void f() { std::cout << "::f()\n"; }
    
    template <typename T>
    class base
    {
    public:
        void f() { std::cout << "base::f()\n"; }
    };
    
    template <typename T>
    class derived
        : public base<T>
    {
    public:
        void g() {
            f();
            this->f();
        }
    };
    
    int main()
    {
        derived<int>().g();
    }
    

    I’m using qualification with this-> in all my code unless some coding guidelines prohibits me from doing so (and I’d consider this aspect of the coding guideline silly and wrong). Of course, in my own code I qualify all names which can be qualified and which aren’t a customization point (e.g., I wouldn’t qualify swap()).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have seen a lot of documentation that describes the correct or recommended format
I have often used, and seen recommended, dom-access structures like this for adding content
Can someone recommend a hosted solution that answers the following requirements (I have seen
I have seen some people in SO commenting that Singleton Pattern is an anti-pattern.
I have seen behaviour in Perforce that I am unable to explain. I took
I have seen many posting this issue in SO. I have gone through those
I have seen this talked about but never answered. Maybe it has and I'm
I have seen this question and its answers and they clear up some of
I have seen in this TechNet article where SharePoint supports .NET 3.5. I've looked
Previously I have always seen example of use of properties and iVars like this...

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.