我创建了以下类
#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;
};
和子类
#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);
};
主要是我尝试为每个对象创建一个对象
#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;
}
为什么我可以创建 Messaging 对象,但 SportMessaging 对象失败?
我环顾四周,怀疑它可能与具有类似 boost::thread_group 的私有复制构造函数的 boost::thread 相关(关于在类中使用 boost::thread_group 的 stackoverflow 帖子)。
然而,似乎两者Messaging("sports message 3")
都会SportMessaging("another sports message",4)
调用它们的复制构造函数,然后调用每个非静态成员的复制构造函数(即包括尝试调用 boost::thread 的复制构造函数)。最后一句中的想法与 'SportMessaging anotherSportMessagingObject = SportMessaging("another sports message",4);' 不起作用,'Messaging aMessObj = Messaging("sports message 3");` 有效。