Error using subclass of class with boost::thread data member

180 views Asked by At

I have created the following class

#include <iostream>
#include <boost/thread.hpp>
#include <boost/date_time.hpp>

class Messaging
{
public:
    Messaging(const std::string& newMessage, unsigned long long maxTimeToDeliver = 12): m_theMessage(newMessage), m_maxTimeToDeliver(maxTimeToDeliver), athread(){};
    virtual ~Messaging(void);

protected:
    std::string m_theMessage;
    unsigned long long m_maxTimeToDeliver;
    boost::thread athread;
};

and the subclass

#include "messaging.h"
#include <iostream>

class SportMessaging :public Messaging
{
public:
    SportMessaging(const std::string newMessage, unsigned long long maxTimeToDeliver = 1): Messaging(newMessage, maxTimeToDeliver) {};
    virtual ~SportMessaging(void);
};

and in main I try to create an object of each

#include "SportMessaging.h"
#include <boost/thread.hpp>
#include <boost/date_time.hpp>
int main()
{
    SportMessaging anotherSportMessagingObject = SportMessaging("another sports message",4);  //gives error C2248: 'boost::thread::thread' : cannot access private member declared in class 'boost::thread'

    Messaging aMessObj = Messaging("sports message 3");  //works

    return 0;
}

Why can I create the Messaging object, but the SportMessaging object fails?

I've looked around and suspect it might be related to boost::thread having a private copy-constructor similar boost::thread_group (stackoverflow post on using boost::thread_group in a class).

However, it seems like both Messaging("sports message 3") and SportMessaging("another sports message",4) would call their copy-constructor and then each of the nonstatic members' copy-constructor (i.e. including trying to call boost::thread's copy-constructor). The idea in the last sentence conflicts with the fact that 'SportMessaging anotherSportMessagingObject = SportMessaging("another sports message",4);' doesn't work and 'Messaging aMessObj = Messaging("sports message 3");` works.

0

There are 0 answers