次のクラスを作成しました
#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 に似たプライベート コピー コンストラクターを持つ boost::thread_group (クラスでの 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");` は動作します。