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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T01:57:36+00:00 2026-06-03T01:57:36+00:00

I have a class template which inherits from a base class template. The base

  • 0

I have a class template which inherits from a base class template.

The base class template has a data member with a member function template which I want to call from within my super class.

I know that in order to disambiguate the call to the member function template, I have to use the template keyword, and I have to explicitly refer to this in the super class.

this->base_member_obj.template member_function<int>();

All this is good and well, except that the codebase I’m using has made the rather unfortunate mistake of importing the entirety of namespace std, and the template member function I’m trying to call is called set. Somewhere in the framework std::set is included, and this causes GCC to think I’m trying to declare a std::set rather than call the member function set.

GCC 4.7 throws an error invalid use of ‘class std::set’

See below for an example showing the error. If you comment out using namespace std the code compiles fine.

Sadly it is not feasible for me to go through the entire codebase, remove every using namespace std call, and prefix every call to anything inside the std namespace with std::

Is there any other way around this?

#include <set>
using namespace std; // comment this out to compile fine

struct blah
{
    template<typename T>
    void set()
    { }
};

template<typename T>
struct base
{
    blah b;
};

template<typename T>
struct super : base<super<T>>
{
    void fun()
    {
        this->b.template set<int>(); // this line breaks
    }
};

int main()
{
    super<int> s;
    s.fun();

    return 0;
}
  • 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-03T01:57:37+00:00Added an answer on June 3, 2026 at 1:57 am

    Well, that’s rather embarrassing for us C++ pushers.

    This is a bug in G++, which also appears in Comeau Test Drive. It’s not a flaw in the language itself. The problem stems from the left-to-right nature of parsing and way C++ grammar skirts ambiguity.

    It is legal to use a non-member, non-base class template in a nested name specifier to a typedef to a base class template. In such a context, a class template with no special relationship to the accessed class can appear after the ->:

    #include <tuple>
    
    template< typename t >
    struct get_holder
        { typedef std::tuple< t > type; };
    
    template< typename ... ts >
    struct inherits
        : get_holder< ts >::type ... {
    
        inherits( ts ... v )
            : get_holder< ts >::type( v ) ...
            {}
    
        template< typename tn >
        void assign_one( inherits &o )
            { this->get_holder< tn >::type::operator= ( o ); } // <- here!
    };
    
    int main() {
        inherits< int, char, long > icl( 3, 'q', 2e8 );
        icl.assign_one< char >( icl );
    }
    

    Since C++ is parsed left-to-right, when the parser hits the ->, it must resolve get_holder before proceeding. The Standard has a special clause §3.4.5/1 [basic.lookup.classref] for this:

    In a class member access expression (5.2.5), if the . or -> token is
    immediately followed by an identifier followed by a <,
    the identifier
    must be looked up to determine whether the < is the beginning of a
    template argument list (14.2) or a less-than operator. The identifier
    is first looked up in the class of the object expression. If the
    identifier is not found, it is then looked up in the context of the
    entire postfix-expression and shall name a class template. If the
    lookup in the class of the object expression finds a template, the
    name is also looked up in the context of the entire postfix-expression
    and

    — if the name is not found, the name found in the class of the object
    expression is used, otherwise

    — if the name is found in the context of the entire postfix-expression
    and does not name a class template, the name found in the class of the
    object expression is used, otherwise

    — if the name found is a class template, it shall refer to the same
    entity as the one found in the class of the object expression,
    otherwise the program is ill-formed.

    Emphasis mine — it would appear that G++ is following this logic despite the template keyword appearing between the . and the identifier set. Furthermore, assuming it’s going down this route, it should have flagged the ambiguity as an error instead of trying to choose the non-member.

    There does appear to be a flaw in the standard’s wording of how to proceed when the template keyword does appear, but it shouldn’t cause the mayhem you see. §14.2 [temp.names]:

    When the name of a member template specialization appears after . or -> in a postfix-expression, or after a nested-name-specifier in a qualified-id, and the postfix-expression or qualified-id explicitly depends on a template-parameter (14.6.2) but does not refer to a member of the current instantiation (14.6.2.1), the member template name must be prefixed by the keyword template. Otherwise the name is assumed to name a non-template.

    Emphasis mine, that text is in error and should read “the name is assumed not to name a member template,” because as in my illustration above it could be part of a nested name specifier. If the text is taken literally as-is, then it could be interpreted to mean the template keyword is required in my illustration, hence could indicate a following non-member template (assuming the language supports such a construct at all), and then your program could be misinterpreted as seen by G++.

    But the design intent is clear, and you do not need to add an artificial nested name specifier blah::, although it is a legal workaround.

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

Sidebar

Related Questions

Let's say we have a template class Area , which has a member variable
I have a template class which has a static pointer-to-member, like this: template<class T,
Say you have a sub class B which inherits from super class A. You
Suppose I have a function which looks like this: template <class In, class In2>
I have a template class with a variadic template member function that I am
I have a template class for which I need to access a protected member
We have a problem using a class template which itself uses function objects in
I have a non-template abstract base class which is used in order to be
I have a SquareMatrix template class which inherits Matrix template class, like below: SquareMatrix.h:
I have a templated class Child which inherits from a non-templated Parent class. When

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.