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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T17:46:41+00:00 2026-05-12T17:46:41+00:00

So I have 2 classes, Bullet and Ship, that are dependent on each other,

  • 0

So I have 2 classes, Bullet and Ship, that are dependent on each other, hence circular inclusion. Since I have Ship’s interface #included into Bullet’s interface, the obvious decision was to forward declare Bullet to Ship.

However, when I first tried this I still got compiler errors. I read up a bit on forward declaration and realized that I was constructing a Bullet in one of Ship’s methods, and Bullet’s default constructor is member initialized, which (and I may be wrong) wouldn’t work because a forward class declaration doesn’t allow Ship to see definitions in the interface (i.e. member initialization).

So I decided I could give up the member init and just defined the constructor in Bullet’s implementation file, however I still receive the same problem with circular dependency.

The message in particular is invalid use of undefined type struct Bullet.

I could just put the interface for Bullet and Ship in the same file, but that’s kind of a last resort. Any assistance regarding this problem is appreciated. Thanks.

Here is the spot where the error occurs:

case SDLK_UP: // Fire
{
    Bullet(*this) fired_bullet; // Create bullet. Line where error occurs.
    fired_bullet.Move(); // Move bullet
    break;
}

Bullet’s default constructor takes an argument of the Ship that is firing the bullet, and that code is in a Ship method.

  • 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-12T17:46:42+00:00Added an answer on May 12, 2026 at 5:46 pm

    You want:

    Bullet fired_bullet(*this);
    

    But your coupling is very tight. What does Bullet need from Ship, and what does Ship need from bullet?

    I assume the bullet needs to know what ship it came from so enemy bullets don’t hurt enemy’s and vice versa. Perhaps you need a team type?

    enum bullet_team
    {
        bullet_player,
        bullet_enemy,
    }
    

    And your ships and enemies will only tell the bullet what team they are on, rather than forcing the bullet to keep track of where it came from:

    About firing, maybe make a BulletManager singleton. Tell the manager you want to make a bullet at a position X, with team orientation Y, and properties Z, and the manager will take care of it for you.

    BulletManager::reference().fire(getPosition(), bullet_player);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have classes that store data, and methods to go get data for individual
I have classes that are named exactly the same across different plug-ins that I
I have classes that are needed in both my web service and my server.
I have classes such as AccountsController, ProductsController etc that all inherit from BaseController. Unity
I have classes as below. public interface ITest <T> { public Set<T> methodHere(); }
I often have classes that are mostly just wrappers around some STL container, like
I want to have classes that can mix only specified traits: class Peter extends
If I have classes that need to be shared between my webapp and Tomcat
I have classes like the following. That is many classes with the same few
I have classes (POJOs) annotated with JPA and populated by Hibernate. Since those objects

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.