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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T20:25:57+00:00 2026-06-14T20:25:57+00:00

While considering creative (ie bizarre) solutions to an odd problem, one particular idea triggered

  • 0

While considering “creative” (ie bizarre) solutions to an odd problem, one particular idea triggered my curiosity. It’s not an idea I’m likely to use, but I’d still like to know if it’s legal according to the standard.

A simple example would be…

class base_t
{
  private:
    //  stuff

  public:
    //  more stuff

    class derived_t : public base_t  //  <--- weirdness here
    {
      //  ...
    };      
};

Part of the weirdness – since derived_t inherits from base_t which contains derived_t, it seems like derived_t contains itself.

So – is this a valid-but-strange-and-scary thing of a similar kind to the curiously recurring template pattern, or is it illegal?

EDIT – I should perhaps mention that the reason I thought of this was trying to avoid some namespace pollution. Having a class as a member avoids introducing another global class, but that second class needs to share a lot from the first.

If it was just one pair of classes it wouldn’t be an issue, but this is for a code generator.

  • 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-14T20:25:58+00:00Added an answer on June 14, 2026 at 8:25 pm

    It’s legal, but maybe not the way you arranged your code. A base class has to be complete at the point when it’s used, but isn’t until the closing brace of the definition. So try forward-declaring the nested class:

    class base_t
    {
      private:
        //  stuff
    
      public:
        //  more stuff
    
        class derived_t;
    };
    
    class base_t::derived_t : public base_t
    {
      //  ...
    };      
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

While considering another problem one question appeared. I do not know how to write
I developed a flashcard program a while back for learning Japanese. I've been considering
I started learning JavaScript a while ago. It's a fairly easy programming language considering
While debugging and keep pressing F5, if the source code does not exist, eclipse
I'm considering the use of JiBX for a project that will have to run
I'm considering to use to implement a cache either JBoss Cache or Ehcache. After
While refactoring one of my projects, i replaced all language ISO Codes like en
I would like to determine whether a list contains any duplicate elements, while considering
Background I am considering various architecture options. While I have used SQL over the
I am considering having a look at Opa . While I am comfortable with

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.