#pragma warning(disable:4275) #include #include #include #include #include using namespace std; class Writer { public: Writer(const string& f) : wfile(f) {} void operator()() { this->file.open(wfile.c_str(), ios_base::trunc); this->file << "A nice little string." << endl; this->file.close(); } private: string wfile; ofstream file; }; int main(int argc, char* argv) { Writer* wrtr; cout << "testning, testning" << endl; wrtr = new Writer("test.txt"); cout << "Writer created" << endl; // Ccomment out either the first or second variant. // First variant, using a boost thread. Doesn't work boost::thread thrd(boost::ref(*wrtr)); cout << "Thread started" << endl; thrd.join(); cout << "Threads joined" << endl; // Second variant, without boost. Works (*wrtr)(); cout << "Writer has been run" << endl; delete wrtr; cout << "Writer deleted" << endl; return 0; }