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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T18:13:28+00:00 2026-05-17T18:13:28+00:00

I have a situation in which A has a reference to a class C

  • 0

I have a situation in which A has a reference to a class C defined inside B, and C has an instance of class B.

When I try to compile the code below, I get “field a has incomplete type“. I assume this is because the compiler does not know how much memory it should allocate for an instance of A.

class A;

class B {
public:
  class C {
    A a;
  };
};

class A {
  A(const B::C& _c) 
    : c(_c)
  {}
  const B::C& c;
};

But when I try to compile this, I get “C in class B does not name a type“:

class B;
class B::C;

class A {
  A(const B::C& _c) 
    : c(_c)
  {}
  const B::C& c;
};


class B {      
public:
  class C {
    A a;
  };
};

How can I convince the compiler that B::C is a real type?

  • 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-17T18:13:29+00:00Added an answer on May 17, 2026 at 6:13 pm

    As an absolute guess, I notice there’s one permutation you haven’t tried:

    class B {
    public:
      class C; // Forward declaration
    };
    
    class A {
      A(const B::C& _c) 
        : c(_c)
      {}
      const B::C& c;
    };
    
    class B::C {
      A a;
      C() : a(*this) {}    // Thanks Nim for pointing this out!
    };
    

    This is quite possibly illegal, but worth a shot I think. If it doesn’t work, then I don’t see any way around the problem.

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

Sidebar

Related Questions

I have the following situation: I have site A, which has it's Mercurial repo,
I have a typical situation. my table has four column. (id, user, col2, status)
In college I took on a class on modern physics, in which we learned
Okay, so for whatever reason I have ended up with a situation where the
The scenario: I’m building a website, which will not Host the images in its
Here is a simple situation. (My apologies my SQL is quite rusty.) (I am
First of all this is all just concept, I have no actual programming done
I know there are plenty of resources on this but I'm having a tough
I am looking for hints on how to debugging a crash in an application
I need to retrieve the orientation of my phone. At the moment i wrote

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.