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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T09:16:03+00:00 2026-05-16T09:16:03+00:00

I have two classes. One is a management class, which stores a bunch of

  • 0

I have two classes. One is a management class, which stores a bunch of worker classes. The workers are actually a templated class.

#include "worker.h"    
class Management {

     private: 
      worker<type1> worker1;
      worker<type2> worker2;
      ...

};

The problem arises due to the fact that the templated classes needs to use Management.

Example:

class Worker{
   ...
};

#include "Worker.inl"

The Worker inl file:

#include "Management.h"  //Circular Dependency!

Worker::Worker(){
    //Management is accessed here
    Management mgmt1();
    mgmt1.doSomething(); //Can't use that forward declaration!
}
...

Normally you would forward declare Management.h in the Worker header file, and call it a day. Sadly, since the class is templated, it is always going to get included.

I guess you can claim that the design is bad, since a templated class shouldn’t be templated if it needs to know this sort of information, but it is what it is, and I have to work with it.

You can also view this question as a microcosm of office life.

  • 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-16T09:16:04+00:00Added an answer on May 16, 2026 at 9:16 am

    If no actual members of Management are referred by worker.inl (i.e. only pointers/references to Management), you could forward declare it:

    class Management;
    
    Worker::Worker(){
        Management* mgmt1; // fine
        Management& mgmt2; // fine
        //mgmt1 = new Management(); // won't compile with forward declaration
        //mgmt2.doSomething(); // won't compile with forward declaration
    }
    

    Otherwise your only option may be to move the method implementations into a cpp file, not included in the headers.

    Note that Worker can not be forward declared, since it is contained by value in Management:

      worker<type1> worker1;
    

    thus the compiler needs to know its full definition at this point.

    You should also consider putting the two class definitions into the same header file, to express that they are interdependent, thus form a component.

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

Sidebar

Related Questions

I have two classes (MVC view model) which inherits from one abstract base class.
I have two classes, and want to include a static instance of one class
I have two classes one of which inherits from the other. Im trying to
I have two classes, one that inherits from the other. The base class is
I have two (unrelated) classes. The first one is Point: typedef std::complex<double> complex_number; class
i have two data classes which hold only data members(no functions). One is CallTask
I have the following two classes, one inherits from the other Class A{ void
I have two classes, one nested in the other. Public Class Operation Public Property
I have two classes in a model . One is Sdr_Layer class . Other
I have two classes, one which is hardware-dependent and one which is not (let's

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.