A route is staticimpossible if your program does not have only one Robot, and an instance of this robot is available statically.
The transfer of the Robottask may be in order, but it may display too much information and prohibit the use of the task using objects other than robots.
, , , Robot . , ++ , .
, POSIX ( void , void), ++ - ish.
, ++ 11, , , , , boost.
( ideone):
#include <iostream>
#include <string>
using namespace std;
class WithNotification {
public:
virtual void notify()=0;
};
class Robot : public virtual WithNotification {
private:
string name;
public:
Robot(const string& n) : name(n) {}
virtual void notify() {cout << name << " has been notified" << endl; }
};
class Task {
private:
WithNotification& onFinished;
public:
Task(WithNotification& f) : onFinished(f) {}
void run() {
cout << "The task is running" << endl;
onFinished.notify();
}
};
int main() {
Robot r1("Quick");
Robot r2("Brown");
Task t1(r1);
Task t2(r2);
t1.run();
t2.run();
}