boost歴は半年ほどです。
クラスのメンバ関数をスレッドでまわそうと考えています。
また、boostでよく用いられるスマートポイントも併用して使用したいです。
ということで、今回単純なクラスの実装を行ったのですが、エラーが出てコンパイルが通りません。
以下、コードになります。
sample.cpp
#include <boost/bind.hpp>
#include <boost/shared_ptr.hpp>
#include <boost/thread.hpp>
using namespace std;
class Sample{
public:
typedef boost::shared_ptr<Sample> ptr;
Sample():x(0),y(0){};
static ptr new_(){
ptr new_(new Sample);
return new_;
}
void start(){
cout<<"ok"<<endl;
}
int x;
int y;
};
int main(){
Sample::ptr sample=Sample::new_();
cout<<sample.x<<endl;
boost::thread ta(boost::bind(&boost::shared_ptr<Sample>::start(),&sample));
ta.join();
}
「環境」
VM ware Lubuntu
「実行結果」
g++ sample.cpp -lboost_system -lboost_thread -lpthread
error: 'Sample::ptr' has no member named 'X'
error: 'start' is not a member of boost::shared_ptr<Sample>
問題となっている部分と、解決策についてご教授頂ければ幸いです。
よろしくお願いいたします。