I use an object to start a boost stream, and it has some public member variables that I modify in the stream (in the () statement). How can I access the member variables of an object outside the stream?
I tried to use a mutex (defined in the class of objects), which is locked both in the operator () of the object and outside, but it does not work.
Here's the code for the stream object:
struct Mouse { int x, y; string port; boost::mutex mutex; Mouse(const string& p) : port(p) { x = y = 0; } Mouse(const Mouse& m) : mutex() { x = mx; y = my; port = m.port; } void operator()() { ifstream ifs; ifs.open (port.c_str(), ios::binary ); if (!ifs.is_open()) { cout << "Impossible d'ouvrir " << port.c_str() << "\n"; exit(0); } while (true)
And this is where I try to access the x and y variables of the mouse:
{ boost::mutex::scoped_lock leftlock(leftMouse.mutex); xLeft = leftMouse.x; yLeft = leftMouse.y; } { boost::mutex::scoped_lock rightlock(rightMouse.mutex); xRight = rightMouse.x; yRight = rightMouse.y; } cout << xRight << " " << yRight << endl;
source share