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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T11:37:34+00:00 2026-05-25T11:37:34+00:00

I was reading this article from this page , so let me present the

  • 0

I was reading this article from this page, so let me present the code:

template <class T> class D: typename C<T>::Base { //#1 error
    D(): typename C<T>::Base(typename C<T>::Base(0)) { } //#2 error, #3 correct
    typename C<T> f() { //#4 error
        typename C<T>::A* p; //#5 correct
        A<T>::B * n;
    }
};
class Q{
    typename C<long>::A * p; // #6 error
}
template <class T, class U> class R{
    typename C<long>::A * p; // #7 optional
}

#3 is correct but I am trying to understand what the author is attempting to convey. He says:

typename #3: correct. Here, typename is used for disambiguating the
type of a parameter. Without typename, the expression C::Base(0)
would be treated as a call to a function called Base. With the
typename prefix, C::Base(0) creates a temporary object of type
C::Base initialized with the argument 0.

Also, if you see a little above that part the author says:

The typename keyword must prefix a dependent name when that name
satisfies the following three rules:

1.It appears inside a template

2.It’s qualified // i am unable to understand this line at all in conjunction with starting para of this quote

3.It isn’t used in a base class specification or a member initialization
list.

I am unable to understand this line (#2 above) at all in conjunction with starting paragraph of this quote. Can you explain what the author means?

  • 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-05-25T11:37:35+00:00Added an answer on May 25, 2026 at 11:37 am

    “Qualified” means that it is not in the same scope, but a subscope of the current one, which also depends on a template. For instance,

    template <class T> struct C {
        typedef int b;
    }
    

    b is a qualified id when referenced in another template e.g

    template<typename T> struct M {
        typename C<T>::b bb;
    }
    

    Relevant quote from the standard (§14.6.3):

    A qualified-id that refers to a type and in which the
    nested-name-specifier depends on a template-parameter (14.6.2) shall
    be prefixed by the keyword typename to indicate that the qualified-id
    denotes a type, forming an elaborated-type-specifier (7.1.5.3).

    And §14.6.2:

    A name used in a template declaration or definition and that is dependent on a template-parameter is
    assumed not to name a type unless the applicable name lookup finds a type name or the name is qualified
    by the keyword typename. [Example:
        // no B declared here
        class X;
        template<class T> class Y {
            class Z; // forward declaration of member class
            void f() {
                X* a1; // declare pointer to X
                T* a2; // declare pointer to T
                Y* a3; // declare pointer to Y<T>
                Z* a4; // declare pointer to Z
                typedef typename T::A TA;
                TA* a5; // declare pointer to T’s A
                typename T::A* a6; // declare pointer to T’s A
                T::A* a7; // T::A is not a type name:
                // multiply T::A by a7; ill-formed,
                // no visible declaration of a7
                B* a8; // B is not a type name:
                // multiply B by a8; ill-formed,
                // no visible declarations of B and a8
            }
        };
    —end example]
    

    And §14.6.7:

    Within the definition of a class template or within the definition of a member of a class template, the keyword
    typename is not required when referring to the unqualified name of a previously declared member
    of the class template that declares a type. The keyword typename shall always be specified when the
    member is referred to using a qualified name, even if the qualifier is simply the class template name.
    [Example:
        template<class T> struct A {
            typedef int B;
            A::B b; // ill-formed: typename required before A::B
            void f(A<T>::B); // ill-formed: typename required before A<T>::B
            typename A::B g(); // OK
        };
    
    The keyword typename is required whether the qualified name is A or A<T> because A or A<T> are synonyms
    within a class template with the parameter list <T>. ]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Firstly, sorry for my English (I'm from China). By reading this article( how to
I'm reading this article and on the part with the query: SELECT node.name FROM
According to this article from Herb Sutter, one should always pick Class Specializing over
After reading this article http://camendesign.com/code/developpeurs_sans_frontieres I have decided to follow what it says and
I've been reading this article from Valve that seems to explain the architecture of
I was reading this article from MSDN on Dependency Injection and I saw a
After reading this article on thedailywtf.com, I'm not sure that I really got the
After reading this article http://lukast.mediablog.sk/log/?p=155 I decided to use mingw on linux to compile
I was reading this article about Double-Checked locking and out of the main topic
I just finished reading this article on the advantages and disadvantages of exceptions and

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.