I'm new to boost library, while practicing an example on bind, i wrote the following code. But, it seems like the 'res' is computed properly but, the correct result is not transmitted back to the signal. Kindly help, what is wrong in the following snippet. The code was compiled and run on http://cpp.sh/
#include <iostream>
#include<boost/signals2.hpp>
using namespace std;
class MathObject{
public:
int AddOps(int op1, int op2);
};
int MathObject::AddOps(int op1, int op2){
int res = op1 + op2;
cout << "Result of AddOps: " << res << endl;
return res;
}
int main(void){
MathObject mObj;
boost::signals2::signal<int(int)> incrementer;
incrementer.connect(boost::bind(&MathObject::AddOps, &mObj, 1, _1));
boost::signals2::signal<int(int)> doubler;
doubler.connect(boost::bind(&MathObject::AddOps, &mObj, _1, _1));
cout << "Incrementer of 5" << incrementer(5) << endl;
cout << "Doubler of 5" << doubler(5) << endl;
}
Output:
Result of AddOps: 6
Incrementer of 51
Result of AddOps: 10
Doubler of 51