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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T13:29:10+00:00 2026-05-25T13:29:10+00:00

duplicate of: "pure virtual method called" when implementing a boost::thread wrapper interface I am

  • 0

duplicate of: "pure virtual method called" when implementing a boost::thread wrapper interface

I am trying to create a more object oriented version of the threads using boost threads.

So I created a Thread class:

class Thread {
public:
    Thread() {}
    virtual ~Thread() { thisThread->join(); }

    void start() { thisThread = new boost::thread(&Thread::run, this); }

    virtual void run() {};

private:
    boost::thread *thisThread;
};

this class creates the thread in start()
like this:

thisThread = new boost::thread(&Thread::run, this);

The problem is that when I create a class that overwrites the run() method, the run() method from Thread is call by the thread instead of the new run() method

for example I have a class that extends Thread:

class CmdWorker: public Thread {
public:
    CmdWorker() : Thread() {}
    virtual ~CmdWorker() {}

    void run() { /* deosn't get called by the thread */ }
};

when I do

Thread *thread = new CmdWorker();
thread.start(); //---> calls run() from Thread instead of run() from CmdWorker

but just to be more clear:

thread.run();  calls the correct run from CmdWorker, (run() is virtual from Runnable)

Any idea why this happens or how it can be fixed ?

NOTE:
I created a function (that has nothing to do with the Thread class)

void callRun(Thread* thread) {
    thread->run();
}

and changed the thread creation to:

thisThread = new boost::thread(callRun, this);

when debugging I noticed that the thread pointer is pointing to a object of type Thread instead of CmdWorker

EDIT:

testcase code at: http://ideone.com/fqMLF
and http://ideone.com/Tmva1

Object seems to be sliced (but this is strange since pointers are used)

didn’t manage to add boost to it

  • 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-25T13:29:11+00:00Added an answer on May 25, 2026 at 1:29 pm

    The answer is in that question:

    "pure virtual method called" when implementing a boost::thread wrapper interface

    Basically, when the boost::thread object begins running, the object it was run against had the
    time to be deleted.

    You have to implement a join method that you call manually before destroying the object.

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

Sidebar

Related Questions

Possible Duplicate: Is there a way to create a SQL Server function to "join"
Possible Duplicate: Is there a way to create a SQL Server function to "join"
Possible Duplicate: What is the difference between "typename" and "class" template parameters? When defining
Duplicate post, see: When do you use the "this" keyword? On almost every project
I know this is almost a duplicate of : The error "Login failed for
Possible Duplicate: When should I use double or single quotes in JavaScript? Do ""
Duplicate: How to "Add Existing Item" an entire directory structure in Visual Studio? I
Duplicate of What is the "< >" syntax within C# Actually i want to
Possible Duplicate: Perplexing Ruby/MySQL Error: "invalid packet: sequence number mismatch" My rails app just
Possible Duplicate: "The 'Microsoft.Jet.OLEDB.4.0' provider is not registered on the local machine"…DNN AccessProviders working

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.