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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T17:30:40+00:00 2026-06-10T17:30:40+00:00

I’m having the following class setup (here only with relevant content): // Message.h class

  • 0

I’m having the following class setup (here only with relevant content):

// Message.h
class Message { };
typedef std::shared_ptr<Message> MessagePtr;
// Task.h
#include "Message.h"

/*
 * On include of Communication.h compilation fails.
 */

class Task {
public:
    send(const MessagePtr &msg) {
        // Call to Communication::send
    }

    MessagePtr recv() {
        // Call to Communication::recv
    }
};

typedef std::shared_ptr<Task> TaskPtr;
// Base.h
#include "Task.h"

class Base {
    std::map<TaskPtr, std::vector<TaskPtr>> taskMap;
};
// Runtime.h
#include "Base.h"

class Runtime : public Base { };
// Communication.h
#include "Base.h"

class Message; // Forward declaration

class Communication : public Base {
public:
    void send(const TaskPtr &caller, const MessagePtr &msg);
    MessagePtr recv(const TaskPtr &caller);
};

My goal is to provide kind of an independent communication layer within Communication to let tasks communicate with each other. The receiver list is defined within taskMap (kind of publish-subscribe where the sender does not know the receivers).

For this purpose my idea is to use a callback function (e.g. with std::bind or similar) from Task to Communication. However, I’m not able to implement this, since whenever I include the Communication Header within Task compilation fails, which is, due to circular includes.

So I’m not sure about how to forward declare send / recv from Communication to use them within Task. I’ve read this question, which is similar and also provides good answers, but I’d like to avoid to place a pointer to Communication within Task. The best possible solution seems to me to introduce kind of forward declaration for the members of Communication, but I’m afraid that I don’t know how to accomplish this.

I’ve also thought about the class setup, whether it fits the purpose, but didn’t come up with a better solution yet.

  • 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-10T17:30:41+00:00Added an answer on June 10, 2026 at 5:30 pm

    You can put the declaration outside of the class. It doesn’t prevent the library to be header-only, as you could inline those functions. You could arrange the functions like:

    // Task.h
    #include "Message.h"
    
    class Task {
    public:
        inline void send(const MessagePtr &msg);
        inline MessagePtr recv();
    //  ^^^^^^
    };
    
    typedef std::shared_ptr<Task> TaskPtr;
    

    // Communication.h
    #include "Base.h"
    #include "Task.h"
    
    class Communication : public Base {
    public:
        void send(const TaskPtr &caller, const MessagePtr &msg);
        MessagePtr recv(const TaskPtr &caller);
    };
    

    // Task.impl.h
    #include "Communication.h"
    
    inline void Task::send(const MessagePtr &msg) {
        // call Communication::send
    }
    
    inline MessagePtr Task::recv() {
        // call Communication::recv
    }
    

    And include Task.impl.h to have the two task methods defined.

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I want use html5's new tag to play a wav file (currently only supported
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I am doing a simple coin flipping experiment for class that involves flipping a
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
Seemingly simple, but I cannot find anything relevant on the web. What is the
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I'm having trouble keeping the paragraph square between the quote marks. In firefox the

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.