The Asio author told me they can't be used as template arguments pre-c++0x. This code runs fine with VC9, but fails with MinGW-GCC 3.4.5. It basically just creates a local class/struct with the goal of having a method to bind and call back later, without having to go outside the scope and declare the entire class/operator() or anonymous namespace. I assume boost::bind/function is/has to use an internal template with the local class as an argument, which is why this fails.
Anybody have a trick up their sleeves to get this or something similar working?
Code:
#include <iostream>
#include <boost/bind.hpp>
#include <boost/function.hpp>
#define CLASS(name, data) struct name { void Call() { data }; }
int main()
{
CLASS(blah, { std::cout << "hi" << std::endl; }) temp;
boost::function<void()> f = boost::bind(&blah::Call, temp);
f();
}
In function `int main()':
error: no matching function for call to `bind(void (main()::blah::*)(), main()::blah&)'
=== Build finished: 1 errors, 0 warnings ===
Is that the error pre-c++0x GCC throws when it gets confused with the local class reference? ie. main()::blah. Yes, this is my crappy replacement for not having local functions, lambdas, or anything decent. Please don't mention Boost.Lambda.
Thanks for any info