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

  • Home
  • SEARCH
  • 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 6849757
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T01:02:04+00:00 2026-05-27T01:02:04+00:00

So my latest error is starting to bug me really bad and I’ve looked

  • 0

So my latest error is starting to bug me really bad and I’ve looked around the internet and the best solution I have come up with is that I have a cyclical #include error, but I’m not sure what is exactly causing that. My include structure looks like the following:

Player.h -includes-> Pawn.h -includes-> Piece.h -includes-> Player.h

I mean, it seems obvious to me that this is a cyclical include problem, but I don’t know how to overcome this. To complicate things, class Pawn extends Piece, and Piece has a boost::weak_ptr back to Player. The reason my includes looks like this is because Player has a vector of Pawns (and other Pieces) but Pawn also needs to call some of Player‘s methods, so I gave the base class Piece a weak_ptr to Player for that.

What is a way that I can design this better so that I don’t have a cyclical include?

  • 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-27T01:02:05+00:00Added an answer on May 27, 2026 at 1:02 am

    You can work around this by using forward declarations; in fact, you should prefer them to including headers in most cases.

    When a header doesn’t need to know about any of the implementation details of another class, you can use a forward declaration for it, instead of including the entire class definition. This basically tells the compiler ‘There’s a class with this name,’ but nothing else.

    // This is a forward declaration. It tells the compiler that there is a 
    // class named Player, but it doesn't know the size of Player or what functions
    // it has.
    class Player; 
    
    struct Piece {
       // This is just a pointer to player. It doesn't need to know any details about
       // Player, it just needs to know that Player is a valid type.
       boost::weak_ptr<Player> player;
    };
    

    As a general rule, if a file only passes around a pointer or reference to a certain type, that type should be forward declared. However, if it tries to actually use an object of that type, it will result in a compiler error. In this case, you need to include the appropriate header.

    In most cases, you’ll want to include the headers for any forward declared classes in the source file, so you can actually use the objects that are being pointed to.

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

Sidebar

Related Questions

Got this error for the first time, I have looked around and cannot find
After figuring out (via SO, of course) that the error for a bad $ftp
I have a solution that uses EF Code First. I recently upgraded all my
I have an error in NetBeans(mobile business application) I have installed JDK (latest version
Problem: Obscure error message http://img66.imageshack.us/img66/6746/confusedg.png Conditions: IE7, SP2, latest flash/java. Only reproducible on one
So Hibernate Supports the latest Version of Firebird, which is really great. But... I
http://localhost/joomla/administrator/ The web browser returns an error that the page does not exist after
adMob was working fine until I update eclipse to latest version, now when starting,
With the latest version of Xcode from Apple, I have the following problem. Upon
I'm trying to implement django-filebrowser into my latest app. I have grappelli installed also.

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.