Boost logo

Boost Users :

From: Ç®ÏþÃ÷ (kyleqian_at_[hidden])
Date: 2008-03-02 09:41:43


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<float (int x, int y)> 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<float ()(int, int),
std::allocator<void> >'(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?



Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net