
AMDG 钱晓明 wrote:
I wrote some code using boost.function. Compiling it both in g++4.13 and vc8, I find that I can not declare a struct in function with operator() and use boost.function to call it when I use g++. Just like this:
int main() { struct int_div { float operator()(int x, int y) const { return ((float)x)/y; }; }; boost::function
f = int_div(); std::cout << f(5, 3) << std::endl; return 0; } When I compile the code above in g++, it give me the error : 请求从 'main()::int_div' 转换到非标量类型 'boost::function '(I use ubuntu chinese.) but when I move the int_div definition outside of main(), It is ok! And the code above VC8 can compile it! why?
The above code is illegal. You are not allowed to pass a local class to a template. Try moving int_div outside main. In Christ, Steven Watanabe