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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T00:31:13+00:00 2026-06-01T00:31:13+00:00

I have tried to solve the problems related to circular dependency in some files

  • 0

I have tried to solve the problems related to circular dependency in some files I have made following that structure:

A.h

#include "B.h"
#include "C.h"
#include "D.h"

namespace NS {

class B;
class C;
class D;

class A {

/* ... */

    A(const A& a) {};

    A(const B& a) {};
    A(const C& a) {};
    A(const D& a) {};

/* ... */
};

}; // NS END

B.h

#include "A.h"
#include "C.h"
#include "D.h"

namespace NS {

class A;
class C;
class D;

class B {

/* ... */

    B(const B& a) {};

    B(const A& a) {};
    B(const C& a) {};
    B(const D& a) {};

/* ... */
};

}; // NS END

C.h

#include "A.h"
#include "B.h"
#include "D.h"

namespace NS {

class A;
class B;
class D;

class C {

/* ... */

    C(const C& a) {};

    C(const A& a) {};
    C(const B& a) {};
    C(const D& a) {};

/* ... */
};

}; // NS END

D.h

#include "A.h"
#include "B.h"
#include "C.h"

namespace NS {

class A;
class B;
class C;

class D {

/* ... */

    D(const D& a) {};

    D(const A& a) {};
    D(const B& a) {};
    D(const C& a) {};

/* ... */
};

}; // NS END

Whatever I try I have some errors from the constructors taking as argument classes in other files, even putting the declaration ahead, seems like it take it the declaration as declaration and definition, and ignore the real definition that is in another file. How could I solve that?

NOTE: I have define guard in each file, just I didnt put it here

  • 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-01T00:31:14+00:00Added an answer on June 1, 2026 at 12:31 am

    if you remove all the #includes in the headers and put them in the source files, everything should compile.

    You don’t need the includes since you have forward declarations which is sufficient in this case since you only use const references to the forward declared classes. (note: previous statements only hold if your sample code mimics your actual code).

    You can also add a seperate header forward.h containing the declarations, instead of repeating yourself everywhere:

    namesapce NS
    {
      class A;
      class B;
      class C;
      class D;
    }
    

    Now make A.h, B.h etc #include forward.h and you do not need the forward declarations in each header anymore.

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

Sidebar

Related Questions

I'm learning functional programming, and have tried to solve a couple problems in a
I have made a script that run various loops and does some SQL inserts.
I have tried the following two statements: SELECT col FROM db.tbl WHERE col (LIKE
I have the following piece of code and I have 3 questions related to
I found some previous questions related to this, but I'm still unable to solve
I have a problem that I tried to ask about previously, but didn't get
I have tried <ul id=contact_list> <li id=phone>Local 604-555-5555</li> <li id=i18l_phone>Toll-Free 1-800-555-5555</li> </ul> with #contact_list
I have tried this... Dim myMatches As String() = System.Text.RegularExpressions.Regex.Split(postRow.Item(Post), \b\#\b) But it is
I have tried what seems like everything - I've done similiar things many times
I have tried to integrate the Picasa API on iPhone, compiles fine, but I

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.