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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T20:48:54+00:00 2026-06-01T20:48:54+00:00

I have a three way cyclic dependency between three header files, each of which

  • 0

I have a three way cyclic dependency between three header files, each of which has one class within it. This is the relevant portion of the Agent2 class:

#ifndef BUYINGJEANS1_H
#define BUYINGJEANS1_H
class Agent2{
    public:
    Agent2(){}

    double getAdvertisingFash(int currentTime, int sFash, int brand){
        Agent1 agent1;
        Agent3 agent3;
        double probabilityOfChangingFashion = (exp((-advertisementArray[currentTime+1][brand]*pow(abs(min(fashionArray[brand]+1,4.0)-sFash),D))+(-alphaArray[2][2]*pow(abs(fashionArray[brand]-sFash),AArray[2][2]))) * (exp((-(agent1.alphaArray[2][1])*pow(abs((agent1.fashionArray[brand])-sFash),AArray[2][1]))))*(exp((-(agent3.alphaArray[2][3])*pow(abs((agent3.fashionArray[brand])-sFash),AArray[2][3])))))/getZScoreAdvertisingFash(currentTime,brand);
        return probabilityOfChangingFashion;
    }
#endif

An equivalent function exists in the Agent1 and Agent3 classes, except Agent1 would use Agent2 and Agent3, and Agent3 would use Agent1 and Agent2.

I know that forward declaration won’t work here because I obviously need to use the members of classes Agent2 and Agent3. When I run a main function in a separate cpp file that uses this code, I receive an undeclared identifier error for Agent1 and Agent3.

Anyone know how I can resolve this in the simplest manner possible?

  • 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-01T20:48:56+00:00Added an answer on June 1, 2026 at 8:48 pm

    You will need to move the body of one or more of your functions into a .cpp file instead of the header. This way, Agent1 and Agent3 can include the Agent2 header without the Agent2 header needing them.

    You only need to move the implementation of the functions of one of these classes to break the cyclic dependency, but you may want to do it for all three to be consistent and avoid similar problems in the future.

    In Agent2.H:

    #ifndef BUYINGJEANS1_H
    #define BUYINGJEANS1_H
    class Agent2{
        public:
        Agent2(){}
    
        double getAdvertisingFash(int currentTime, int sFash, int brand);
    }
    #endif
    

    And in Agent2.cpp:

    #include "Agent2.H"
    
    #include "Agent1.H"
    #include "Agent3.H"
    double Agent2::getAdvertisingFash(int currentTime, int sFash, int brand)
    {
        Agent1 agent1;
        Agent3 agent3;
        double probabilityOfChangingFashion = (exp((-advertisementArray[currentTime+1][brand]*pow(abs(min(fashionArray[brand]+1,4.0)-sFash),D))+(-alphaArray[2][2]*pow(abs(fashionArray[brand]-sFash),AArray[2][2]))) * (exp((-(agent1.alphaArray[2][1])*pow(abs((agent1.fashionArray[brand])-sFash),AArray[2][1]))))*(exp((-(agent3.alphaArray[2][3])*pow(abs((agent3.fashionArray[brand])-sFash),AArray[2][3])))))/getZScoreAdvertisingFash(currentTime,brand);
        return probabilityOfChangingFashion;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there any way to have this: [one[two]][three] And extract this with a regex?
I have three big header files (4.5MB and more), with huge static arrays inside.
I have three tables: tbl_tag tbl_post tbl_post_tag(post_id, tag_id) tbl_users . Each Post has multiple
I have three texboxes and one slider which changes their Text properties. What i
Is there a way in .NET to have a class property have a second
I have three zipped folders named [1,2,3] each contains the same project 1 being
I have three classes which implement the same protocol, and have the same parent
I have three projects in my C# 4 solution. MooDB: Has my domain objects
Question Is there a way to split up each class based upon a prefix
The way a part of my database is designed I have three tables: Partners

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.