C++ monitor class/wrapper using condition variables
问题 I'm trying to create a wrapper class W in C++, which is constructed with a pointer to a generic object OBJ . When you call one of OBJ methods through W , W (containing a condition variable cv ) issues a cv.wait() before calling OBJ method and a cv.notify() when OBJ method has finished. I've been able to do it with inheritance for a specific class, but would like a generic approach like the one described above. This is the inheritance approach: struct A { virtual void foo(int i) { bar = i; };