Hello I've run into a problem when using boost::bind, and I cannot figure why it wont compile.
I'm using bind to create function bindings for my console system, so that the console can set and get variables of a class without the classes depending on eachother.
My console has a ConsoleItem which has a boost::function<std::string (void)> get_function and boost::function<void (std::string)> set_function.
From the console I can call Add, which then creates a ConsoleItem with functions as argument: void Add(std::string name, boost::function<void (std::string)> set_function, boost::function<std::string (void)> get_function).
I can then create a ConsoleItem doing this:
Console con;
con.Add("name", bind(&ClassWithVariable::Variable, &X, bind(lexical_cast<int, std::string>, _1 )), bind( lexical_cast<std::string, int>, bind(&ClassWithVariable::Variable, &X)) );
Where the function Variable is int Variable(void) and void Variable(int) -- get and set respectively.
I can now get and set via the console using the name as identifier and pass a string as argument for setting and do a boost::lexical_cast when getting.
The problem however is that I am lazy and therefor I to create functions for adding each of the item types I can so that the interface is more like this:
// one of these functions for each type I can add.
// Possibly only named Add with different boost::function arguments
void AddInt(std::string name, boost::function<void (int)> set_function, boost::function<int (void)> get_function) {
Add(name, boost::bind(set_function, boost::lexical_cast<int, std::string>, _1), boost::bind(boost::lexical_cast<std::string, int>, get_function)); // does not compile
}
So that I can call add a console item like this:
Console con;
con.AddInt("hello", bind(&ClassWithVariable::Variable, &X, _1), bind(&ClassWithVariable::Variable, &X) );
The problem is, however, that the code with
AddInt does not compile, and I have no idea why.
Any help appreciated.