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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T13:08:46+00:00 2026-05-27T13:08:46+00:00

class c { public: int id; boost::thread_group thd; c(int id) : id(id) {} void

  • 0
class c
{
public:
    int id;
    boost::thread_group thd;
    c(int id) : id(id) {}
    void operator()()
    {
        thd.create_thread(c(1));
        cout << id << endl;
    }


};

I created class c. Each class object creates threads in order to process the work. However I get this weird message when I compile this

: error C2248: ‘boost::thread_group::thread_group’ : cannot access private member declared in class ‘boost::thread_group’

Besides, just assume is no recursive calling problems.

  • 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-27T13:08:46+00:00Added an answer on May 27, 2026 at 1:08 pm

    The issue is that the way your code is set up is passing a copy of your object to create a new thread.

    You are getting the error because the copy constructor of boost::thread_group is private, so you cannot copy an object of class c. You cannot copy an object of class c because the default copy constructor tries to copy all members, and it cannot copy boost::thread_group. Thus the compiler error.

    The classic solution to this would be to either write your own copy constructor that does not try to copy boost::thread_group(if you actually want one unique thread_group per call) or to store boost::thread_group in a pointer of some kind that can be copied(which would share the group, and is probably what you want).

    NOTE:

    It is usually simpler to not write your own operator(), and just pass along boost::functions instead. This would be done with

    #include <boost/thread.hpp>
    #include <iostream>
    using namespace std;
    class c
    {
    public:
        boost::thread_group thd;
    
        void myFunc(int id)
        {
            boost::function<void(void)> fun = boost::bind(&c::myFunc,this,1);
            thd.create_thread(fun);
            cout << id << endl;
        }
    
    
    };
    

    Note that whatever is in the class c is shared, and whatever is passed by value in the function call is not shared.

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

Sidebar

Related Questions

public class MyClass { public int Age; public int ID; } public void MyMethod()
so i have a class like: class mySafeData { public: void Set(int i) {
class ThreadWorker { public: ThreadWorker(void); virtual ~ThreadWorker(void); static void DoSomething(); }; int main() {
#include <boost/ptr_container/ptr_vector.hpp> #include <iostream> using namespace std; class Derived { public: int i; Derived()
Given the following class public class Foo { public int FooId { get; set;
Consider the following class public class Class1 { public int A { get; set;
Say I have this class: public class Account { public int AccountID { get;
I have the following class: public class Account { public int AccountID { get;
I have the following class: public class Day { public int Date { get;
class Foo { public int A { get; set; } } class Program {

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.