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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T11:31:46+00:00 2026-05-18T11:31:46+00:00

I am creating a new boost::thread using boost::bind , and storing it in a

  • 0

I am creating a new boost::thread using boost::bind, and storing it in a boost::shared_ptr.
I am passing a function and argument to the boost::thread, but when the thread is started, it does not correctly call the copy constructor for the function argument.

The thread creation method I’m using is a very common Boost pattern, so I don’t think that’s where the problem is:

void myclass::myfunc() {
   Workflow wfOriginal;
   boost::shared_ptr<boost::thread>(
       new boost::thread(boost::bind(&myclass::anotherfunc, this, wfOriginal)));
}
// ...
void myclass::anotherfunc(Workflow wfCopied) {
   // Doing something
}

I am trying to copy the Workflow from myfunc() to anotherfunc().
Workflow contains a collection, so I have provided a copy constructor that copies the elements inside the existing collection to the new Workflow.

Unfortunately, when anotherfunc() is called by the new thread, the collection inside wfCopied is empty!
I can tell that the Workflow object was partially copied, because other members like strings and ints have been copied, but the elements in the collection have not.

I have verified that the copy constructor works correctly by testing it with this code:

Workflow wf;
// ... insert some elements into wf...
Workflow wf1 = wf;
// wf1 has the same elements

I want to emphasize that my tests showed me that Workflow‘s copy constructor works fine.
But for completeness, here is the copy constructor for Workflow:

Workflow::Workflow(const Workflow& workflow) {
    this->_id = workflow._id;
    (this->_tasks).clear();
    Workflow::TaskCollectionConstIterator it;
    for (it = (this->_tasks).begin(); it < (this->_tasks).end(); it++)
        (this->_tasks).push_back(*it);
}

Can anyone help me?

  • 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-18T11:31:47+00:00Added an answer on May 18, 2026 at 11:31 am

    It seems your copy constructor is flawed. You’re copying from your empty vector to your vector. Which results in nothing being copied.

    I think you mean:

    for (it = (workflow->_tasks).begin(); it < (workflow->_tasks).end(); it++)
        (this->_tasks).push_back(*it);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

There is a function assign in Boost.Asio sockets, however I'm looking for something like
I'm pretty new to boost. I needed a cross platform low level C++ network
I'm creating event system. It's based under boost::signals. To make the work easier I'm
I've stared at the Boost.Interprocess documentation for hours but still haven't been able to
I have a method void foo(list<shared_ptr<Base>>& myList); Which I'm trying to call with a
I'm creating a library to allow OCaml/Haskell-like algebraic data types and pattern matching. The
I have the following code: Class B { void generator() { // creating random
I was looking at the boost serialization library, and the intrusive way to provide
In VS 2010RC I have to specify configuration properties and specifically included path every
Update 3 : Never mind. I kinda got what I was looking for. 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.