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

  • Home
  • SEARCH
  • 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 8588089
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T22:43:42+00:00 2026-06-11T22:43:42+00:00

I am developing a code using Boss-Worker model pattern. I have a doubt. The

  • 0

I am developing a code using Boss-Worker model pattern. I have a doubt.
The list which the Boss will be adding to, is a member of the Boss class.
In order for the Worker to access it, I am making the Worker class inherit from Boss.

1) Is this the right way to share the list between the Boss & Worker?
2) I am facing ambiguous inheritance in my code. How can I solve it?

ThreadClass

#include <pthread.h>
class ThreadClass
{
public:
    virtual int start();
    virtual void join();
    virtual void execute() = 0; //Each derived class will implement this
    virtual ~ThreadClass() {}
    ThreadClass() {}
private:
    ThreadClass* Tptr;
};

Boss

#include "ThreadClass.h"
#include <list>

class Boss : public virtual ThreadClass
{
public:
    virtual void execute();
    Boss() {}   
    ~Boss() {}  

protected:
    std::list<int> Mylist;   //To be shared with the worker
};

Worker

#include "ThreadClass.h"
#include "Boss.h"
class Worker : public Boss, public ThreadClass  //Getting error:Ambiguous ThreadClass
{
public:
    virtual void execute();
    Worker() {} 
    ~Worker() {}    
};

Worker is inheriting from Boss & ThreadClass because:

1) Worker needs access to the list from Boss
2) Worker needs threading functions from ThreadClass

  • 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-11T22:43:43+00:00Added an answer on June 11, 2026 at 10:43 pm

    The list which the Boss will be adding to, is a member of the Boss class. In order for the Worker to access it, I am making the Worker class inherit from Boss.

    This is categorically not a good reason for one class to inherit from another. Usually, Worker should inherit from Boss if and only if you can substitute a Worker in any place that you could use a Boss. Conceptually, this is not the case here.

    If you want to provide access to Boss‘s list of int then, if the Worker knows about the Boss provide and accessor for it in Boss or (possibly) make Worker a friend of Boss.

    If you don’t want Worker to know about Boss but instead have Boss know about Workers then make Boss pass the list to the Worker either at construction time or at a suitable time later.

    Providing access to something is not a reason for making one class derive from another.

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

Sidebar

Related Questions

I'm developing application using backbone.js & jquery. I have following code in model: runReport:
I'm developing some code which reads file names from an sd-card (using FatFs) and
We have been developing code using loose coupling and dependency injection. A lot of
I've spent the last week developing code to connect to a Web Service using
I am developing an android app using code from a normal java application. In
I am developing a site to add events to a Google Calendar using code
We're developing a Qt project using the Code::Blocks IDE with the QtWorkbench plugin. We'd
I am developing an Django application using the Django 1.3.1 release : https://code.djangoproject.com/browser/django/tags/releases/1.3.1 I
I am developing a application using PHP. Some example code is here. $url =
I am developing a ASP.NET MVC 3 application, i am using entity framework code

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.