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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T14:34:20+00:00 2026-05-13T14:34:20+00:00

EDIT: SOLVED I’m working on a multi-threaded project right now where I have a

  • 0

EDIT: SOLVED

I’m working on a multi-threaded project right now where I have a base worker class, with varying worker classes that inherit from it. At runtime, the worker classes become threads, which then perform work as needed.

Now, I have a Director I’ve written which is supposed to maintain an array of pointers to all of the workers, so that it can retrieve information from them, as well as modify variables within them later.

I did this by creating a pointer to a pointer of the base class:

baseWorkerClass** workerPtrArray;

Then in the constructor of the Director, I dynamically allocate an array of pointers to the base worker class:

workerPtrArray = new baseWorkerClass*[numWorkers];

In the constructor of each worker thread, the worker calls a function in the director which is meant to store the pointer of that worker in the array.

Here’s how the director stores the pointers:

Director::manageWorker(baseWorkerClass* worker)
{
    workerPtrArray[worker->getThreadID()] = worker;
}

Here is an example of a worker variant. Each worker inherits from the base worker class, and the base worker class contains pure virtual functions which should exist in all worker variants, as well as a few variables which are shared between all workers.

class workerVariant : protected baseWorkerClass
{
    public:

    workerVariant(int id)
    : id(id)
    {
        Director::manageWorker(this);
    }

    ~workerVariant()
    {
    }

    int getThreadID()
    {
        return id;
    }

    int getSomeVariable()
    {
        return someVariable;
    }

    protected:

    int id;
    int someVariable
};

Then the baseWorkerClass looks something like this:

class baseWorkerClass
{
public:

    baseWorkerClass()
    {
    }

    ~baseWorkerClass()
    {
    }

    virtual int getThreadID() = 0;
    virtual int getSomeVariable() = 0;
};

After each worker variant is done initializing, I should end up with an array of pointers to baseWorkerClass objects. This means I should be able to, for example, get the value of a given variable in a certain worker using its ID as the index to the array, like so:

workerPtrArray[5]->getSomeVariable(); // Get someVariable from worker thread 5

The problem is that this code causes a crash in a Windows executable, without any explanation of why, and in Linux, it says:

pure virtual method called
terminate called without an active exception
Aborted

I could’ve sworn I had this working at some point, so I’m confused as to what I’ve screwed up.


Actual unmodified code that has the problem:

Worker variant header: http://pastebin.com/f4bb055c8
Worker variant source file: http://pastebin.com/f25c9e9e3

Base worker class header: http://pastebin.com/f2effac5
Base worker class source file: http://pastebin.com/f3506095b

Director header: http://pastebin.com/f6ab1767a
Director source file: http://pastebin.com/f5f460aae


EDIT: Extra information, in the manageWorker function, I can call any of the pure virtual functions from the pointer “worker,” and it works just fine. Outside of the manageWorker function, when I try to use the pointer array, it fails.

EDIT: Now that I think about it, the thread’s entry point is operator(). The Director thread is created before the workers, which may mean that the overloaded parenthesis operator is calling pure virtual functions before they can be overridden by the child classes. I’m looking into this.

  • 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-13T14:34:20+00:00Added an answer on May 13, 2026 at 2:34 pm

    The problem appears to be that Director::manageWorker is called in the constructor of workerVariant instances:

    Director::manageWorker(baseWorkerClass* worker) {
        workerPtrArray[worker->getThreadID()] = worker;
    }
    

    Presumably getThreadID() isn’t a pure virtual function or you would have (hopefully!) gotten a compiler error about not overriding it in workerVariant. But getThreadID() might call other functions which you should override, but are being invoked in the abstract class. You should double check the definition of getThreadID() to make sure you’re not doing anything untoward that would depend on the child class before it’s properly initialized.

    A better solution might be to separate this sort of multi-stage initialization into a separate method, or to design Director and baseWorkerClass such that they don’t have this sort of initialization-time interdependency.

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

Sidebar

Ask A Question

Stats

  • Questions 468k
  • Answers 468k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer the function header will only work if no output has… May 16, 2026 at 2:15 am
  • Editorial Team
    Editorial Team added an answer Yes, you can use wildcard mappings to condense your two… May 16, 2026 at 2:15 am
  • Editorial Team
    Editorial Team added an answer You are correct; there is no such thing as an… May 16, 2026 at 2:15 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.