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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T13:30:36+00:00 2026-05-24T13:30:36+00:00

What I read in the C++ standard about injected class names contradicts (as I

  • 0

What I read in the C++ standard about injected class names contradicts (as I see it) with the behavior of a sample program I will present shortly. Here’s what I read:

  • From 3.4 (paragraph 3)

    The injected-class-name of a class (clause 9) is also considered to be
    a member of that class for the purposes of name hiding and lookup.

  • From 9 (paragraph 2)

    A class-name is inserted into the scope in which it is declared
    immediately after the class-name is seen. The class-name is also
    inserted into the scope of the class itself; this is known as the
    injected-class-name. For purposes of access checking, the
    injected-class-name is treated as if it were a public member name.

From these I understand that the following is a well-formed translation unit and it compiles successfully.

#include <vector>
class X: std::vector<int>
{
   vector mem;
};

However, I would suppose that the following should have produced an error, but it doesn’t

#include <vector>
class X: std::vector<int>, std::vector<char>
{
   vector mem; //compiles OK... mem is apparently std::vector<int>
};

Since the name vector is injected into both std::vector<int> and std::vector<char> as as if a public member name, then it should be inherited by X and therefore the name vector in X should be ambiguous. Am I missing something?

P.S. I am using MSVC9.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-05-24T13:30:37+00:00Added an answer on May 24, 2026 at 1:30 pm

    I found it! It’s right there in the standard! I was right! It should be ambiguous!

    Clause 14.6.1 Paragraph

    A lookup that finds an injected-class-name (10.2) can result in an
    ambiguity in certain cases (for example, if it is found in more than
    one base class). If all of the injected-class-names that are found
    refer to specializations of the same class template, and if the name
    is followed by a template-argument-list, the reference refers to the
    class template itself and not a specialization thereof, and is not
    ambiguous. [Example:

    template <class T> struct Base { };
    template <class T> struct Derived: Base<int>, Base<char> 
    { 
        typename Derived::Base b; // error: ambiguous typename 
        Derived::Base<double> d;  // OK 
    };
    

    —end example]

    Bottom line: This is yet another Microsoft compiler BUG. Disabling language extensions doesn’t help either.

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

Sidebar

Related Questions

I read this about class in the C++ standard document: A class is a
I read some other posts here on stackoverflow about passing parms to a class
What's ActivePython actually about? From what I've read it's just standard Python with OpenSSL
I read a bit about a previous attempt to make a C++ standard for
I read and reread the relevant clauses about ODR in the C++ standard, but
I've read quite a bit about initialization of static class variables in c++ and
I read about standard streams . My understanding is old fashioned programs that don't
I have a question about the buffering in standard library for I/O: I read
I thought I read about a C standard library function recently that was able
I tried to read on the IEEE standard about floating point implementation but it

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.