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 9191259
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T20:38:31+00:00 2026-06-17T20:38:31+00:00

I had the same problem as this previous question here: Use of undeclared identifier

  • 0

I had the same problem as this previous question here:
Use of undeclared identifier in C++ with templates and inheritance

To sum it up, we try to access a template class’ protected attribute from a child class. The described way to do this would be to use this->attribute instead of only attribute.
The thing is, I was wondering how come visual studio 2012 didn’t need to add the this-> in front of the variable reference for the program to compile and execute properly. I was also wondering if there was a way to have that feature in gcc or other compilers on OS X.

EDIT:
Here is the code I used to test this out in visual studio 2012.

//file a.h

template<class T>
class a
{
public:
    a(){value = 2;};
protected:
    T value;
};

template<class T>
class b: public a<T>
{
public:
    T getValue(){return value;};
};

//file main.cpp
#include <iostream>
#include "a.h"
using namespace std;
int main()
{
    b<int> myTest;
    cout<<myTest.getValue();
    system("pause");
    return 0;
}

This doesn’t compile using g++ but does using visual studio 2012.

  • 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-17T20:38:32+00:00Added an answer on June 17, 2026 at 8:38 pm

    I believe the part of the standard that describes argument dependent lookup rule applicable in this case is §14.6.2/3, which states the following:

    In the definition of a class template or a member of a class template,
    if a base class of the class template depends on a template-parameter,
    the base class scope is not examined during unqualified name lookup
    either at the point of definition of the class template or member or
    during an instantiation of the class template or member.

    Since your base class depends on a template parameter, the dependent base class scope should not be examined. However, some compilers had this wrong. For example, GCC was doing extra dependent base class scope lookups, which was fixed only in version 4.7 (Bug# 24163, 29131). I do not have an insight as for why Visual Studio compiler allows it. But if it does then it is clearly not standard compliant in this regard. You should not depend on that bug and definitely should not look for compilers with similar bugs to depend on.

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

Sidebar

Related Questions

Seems like just yesterday I had this same problem with Play! v1. After trying
This is the same project as the other question I had. I'm wondering how
I had a previous question that touched this topic ( Rails: how to get
In my previous question on this portal, I had asked about some insight about
This is my first post here. My question is similar to a previous thread
I have the same question for Maven that someone had about Ant ( How
I asked this question before and people gave me a solution to my problem
First: This is not a repeat of this question . Same script, but different
In contrast to my previous question , i'll try to give my requirements. I
My problem could be solved if Scanner class had previous() method on it. I

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.