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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T00:11:19+00:00 2026-06-12T00:11:19+00:00

Is the following code valid with C++ standard? It’s strange that C::B would work

  • 0

Is the following code valid with C++ standard? It’s strange that C::B would work because struct B is in A’s namespace. But it does compile fine with gcc.

struct A { struct B {}; };
struct C : public A::B {};
struct D : public C::B {};

If this is standard conforming C++, what are reasonable applications for this construct?
Thanks.

  • 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-12T00:11:21+00:00Added an answer on June 12, 2026 at 12:11 am

    Yes, it’s valid C++. A class in its own scope (so both B and B::B refer to the same class B), and a class’s parent class is in its own scope. So since B is in C‘s scope and B is in its own scope, C::B refers to B which is A::B.

    (Side note: do not confuse a namespace with a scope.)

    C++03 §9 paragraph 2 says:

    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.

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

Sidebar

Related Questions

I would like to know if the following code are valid. The original intension
Can somebody explain why the following code is not valid? Is it because the
The following code yields an error error: ‘struct Foo’ is not a valid type
I recently came across the following piece of code. It doesn't look valid because
Following code does destroy records as intended, but the callback is inherited from one
I have the following code in Groovy 1.8.5 and to me it looks valid.
I'm getting the following error whenever my code creates a DataTableReader from a valid
Why is the following code valid when I am using a <div> inside a
Can static variables be initialized in a method? Is the following code valid? Thank
What is the set of valid outputs for the following, according to the standard?

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.