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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T20:19:55+00:00 2026-05-17T20:19:55+00:00

I have this situation (two classes with two different header files): b.h #include a.h

  • 0

I have this situation (two classes with two different header files):

b.h

#include "a.h"

class B {
      friend void  B* A::create(void);
   private:
     int x;
};

a.h

#include "b.h"

class A {
   public:
     void B* create(void);
   ...
};

basically class A creates “B” objects. I want to give the creation function create() access to modify the private member ‘x’ of class B. I want to simulate the ‘internal’ keyword in C#, but at a more granular level.

The problem I have is that I end up with a circular header reference. b.h wants to come after a.h, but a.h wants to come after b.h. What is the proper way of doing this? Do I need to resort to void* ptrs? Since I only create one type of object, i don’t think I need the factory pattern. Hopefully I’m missing something simple.

  • 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-17T20:19:55+00:00Added an answer on May 17, 2026 at 8:19 pm

    What you need is a “forward declaration”. Basically you don’t include the classes’ headers in other classes’ headers (unless you want to use composition, then you have to). In your case, it’d look like this:

    // B.h
    class A;
    class B {
        // declare pointers to A freely
    };
    

    And the other way round in A.h.

    You’d probably need to include A.h in B.cpp (and the other way round) to be able to actually dereference those pointers to access fields, but your problem with circular header inclusion is now gone.

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

Sidebar

Related Questions

This is the situation: I have two tables where the one references the other
So, I have this situation where I need to see if an object is
During coding I frequently encounter this situation: I have several objects ( ConcreteType1 ,
The situation is this: You have a Hibernate context with an object graph that
This is often situation, but here is latest example: Companies have various contact data
I know questions of this kind have been asked before, but my situation differs
I have somehow misconfigured fingers. This leads to a very annoying situation. I select
Here is the situation. This small company I'm working with wants to have a
I have two classes, Foo and Bar, in a Django app (on AppEngine if
I have two files from a C program. I guess both belong to quite

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.