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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T05:20:20+00:00 2026-06-01T05:20:20+00:00

This question covers when and why the typename and template disambiguators are needed in

  • 0

This question covers when and why the typename and template disambiguators are needed in C++ template code.

Is it valid to use these disambiguators in cases where they are not needed in C++03? How about in C++11?

  • 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-01T05:20:21+00:00Added an answer on June 1, 2026 at 5:20 am

    It’s valid in conforming C++03/C++11 compilers, for some definition of “valid.”

    C++03 ISO/IEC 14882:2003 §14.2.5:

    [ Note: just as is the case with the typename prefix, the template prefix is allowed in cases where it is not strictly necessary; i.e., when the expression on the left of the -> or ., or the nested-name-specifier is not dependent on a template-parameter. ]

    C++11 ISO/IEC 14882:2011 §14.2.5:

    [ Note: As is the case with the typename prefix, the template prefix is allowed in cases where it is not strictly necessary; i.e., when the nested-name-specifier or the expression on the left of the -> or . is not dependent on a template-parameter, or the use does not appear in the scope of a template. —end note ]

    Note that you can’t use template when the member in question isn’t actually a template—you aren’t allow to lie with it. Also note that for typename, the type has to be a qualified type (e.g. X::Y, not just X). C++11 also changed it so that you don’t have to be in the scope of a template, whereas C++03 required you to be in a template. Also note that compilers are likely to differ on whether they actually let you do this. Under Clang, for instance, this warns under the flag -Wc++11-extensions.


    Here are some examples, assuming the following definition:

    struct X {
        typedef int Y;
        template <typename T> static void foo();
        static void bar();
        template <typename T> static void baz(T);
    };
    

    Invalid in both C++03 and C++11:

    template <typename T>
    void foo() {
        typename int z = 0; // int is not a qualified name.
        X::template bar();  // X::bar is not a template.
        X::template baz(z); // no template argument list.
    }
    

    Invalid in C++03, valid in C++11 (but produces a warning on my copy of Clang):

    void bar() {
        typename X::Y z = 0;    // not in the body of a template, so
        X::template foo<int>(); // no possibility of dependent names.
    }
    

    Valid in both C++03 and C++11:

    template <typename T>
    void baz() {
        typename X::Y z = 0;    // not a dependent name, so 'typename'
        X::template foo<int>(); // isn't strictly necessary.
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Just came across this article about NOSQL patterns (not mine). It's covers lots of
I am not sure the title of this question covers what I mean. In
G'day, Edit: While this question covers a situation that can arise in programming a
This question was asked quite some time ago, and while it covers possible solutions
This question is about programming small microcontrollers without an OS. In particular, I'm interested
This question covers a broad range of programming languages; however, I am specifically working
I have a question about regex/Python. Sorry if this topic has been discussed millions
(Note: Please do not mark this question as duplicate. This question is based on
This is a beginner's question I'm afraid: I have an UIText which covers the
I found this question already on SO, but it only covers CF, so my

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.