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

  • Home
  • SEARCH
  • 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 1064057
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T18:52:25+00:00 2026-05-16T18:52:25+00:00

I require some clarification on the question why do we need the scope resolution

  • 0

I require some clarification on the question why do we need the scope resolution operator or this pointer to access publicly inherited members from a template base class.
As I understand it is for adding clarity but then how does this add any further clarity than just point that it is a member of the class.

To make my question clearer I have added some code.

#include <iostream>
using namespace std;

template <class T, class A>
class mypair {
        public:
         T a, b;
  public:
    mypair (T first, T second)
      {a=first; b=second;}

        virtual void printA() 
        {   
        cout<<"A"<<a<<endl;
        cout<<"B"<<b<<endl;
        }   
};







template <class T, class A>
class next: mypair<T,A>
{
public:

        next (T first, T second) : mypair<T,A>(first, second)
        {   
        }   

        void printA() 
        {   
        cout<<"A:"<<mypair<T,A>::a<<endl; // this->a; also works 
        cout<<"B:"<<mypair<T,A>::b<<endl; // this-b;  also works
        }   

};


int main () {
  next<double,float>  newobject(100.25, 75.77);
  newobject.printA();
  return 0;
}

Output:

A:100.25
B:75.77

If i remove the scope(or this operator) then the out of scope error comes.
But why do we need a scope for publicly inherited members.

Some thoughts on this would be great.

  • 1 1 Answer
  • 1 View
  • 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-05-16T18:52:25+00:00Added an answer on May 16, 2026 at 6:52 pm

    Refer to Name lookup – Using the GNU Compiler Collection (GCC)

    By adding explicit prefix mypair<T, A>, or this->, you make printA template argument dependent. Then the definitions will be resolved during template instantiation stage.

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

Sidebar

Related Questions

I just need some clarification in regards to unit testing with VS2010. Currently, we
Clarification : As per some of the comments, I should clarify that this is
I'm working on a Google App Engine program that will require some basic spell
I'm looking to design an application that will require some deep control over IP
i have a validation class which needs improving. If I require some custom validation
I have a singleton object that use another object (not singleton), to require some
Quick yes/no - I'm building an AJAX application and some scripts require authentication. Can
I have a asp.net mvc application. Some pages require SSL, is there a way
I have some classes in my app that don't require an ID to be
I am loading some template files into my application using require.js like so: define(function(require)

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.