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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T22:53:59+00:00 2026-05-17T22:53:59+00:00

The facts: I have two predominant classes: Manager and Specialist. There are several different

  • 0

The facts:

  • I have two predominant classes: Manager and Specialist.
  • There are several different types of Specialists.
  • Specialists often require the help of other Specialists in order to get their job done.
  • The Manager knows all of the Specialists, and initially each Specialist knows only their Manager. (This is the problem.)
  • At runtime, the Manager creates and stores a list of Specialists. Then the Manager iterates through the list and asks each Specialist to initialize. During their initialization, each Specialist asks the Manager to supply them with other Specialists that fulfill some description. Once this is complete, the Manager then goes into a loop during which the Specialists are asked sequentially to perform their specialized task.

To me it seems that this is a decent pattern, but since a Manager has a list of Specialists and a Specialist has a Manager I’m getting circular dependency problems.

Is this a case where I should somehow forward declare the existence of one class from another? (If so, how?) Or should I use some design pattern to fix this problem? (If so what?) Also… I though the pattern itself was pretty o.k. so I wouldn’t mind someone helping me understand why this is a bad thing.

  • 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-17T22:54:00+00:00Added an answer on May 17, 2026 at 10:54 pm

    In both cases, forward declare the other class:

    Manager.h

    class Specialist;
    
    class Manager
    {
        std::list<Specialist*> m_specialists;
    };
    

    Specialist.h

    class Manager;
    
    class Specialist
    {
        Manager* m_myManager;
    };
    

    The only time you need to bring in the header file for a class is when you need to use a member function or variable within that class, or need to use the class as a value type etc. When you only need a pointer or reference to a class, a forward declaration will suffice.

    Note that forward declarations aren’t just for solving circular dependencies. You should use forward declarations wherever possible. They are always preferable to including an extra header file if it is at all viable.

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

Sidebar

Related Questions

I have a dimension (SiteItem) has two important facts: perUserClicks perBrowserClicks however, within this
I have the next two facts loaded in my prolog interpreter: foo(U+V,1). foo(U*V,2). Now
The facts: I have a library called A . I have two projects, B
I have two almost identical classes, in fact every member function is identical, every
I have two (5 in fact) domain classes, ClassA and ClassB and have to
I have the facts table with two date columns: StartDate and FinishDate: And I
I have two convex polygons in 3D. They are both flat on different planes,
I actually have right now two questions: 1) What font faces are preferred for
I have an irregular mesh which is described by two variables - a faces
I have a super-simple query in a star schema. One fact, two dimensions. 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.