
12 Apr
2004
12 Apr
'04
1:56 p.m.
Thorsten Ottosen wrote:
My point is that if the prototype was
void square( int& );
then
function< void(void) > f( int x ) { return bind( square, x*5 ); }
should not compile.
Why should it not compile? int increment(int & x) { return ++x; } template<class F> void test_nonconst(F f) { std::cout << f() << '\n'; std::cout << f() << '\n'; std::cout << f() << '\n'; } template<class F> void test_const(F const & f) { std::cout << f() << '\n'; std::cout << f() << '\n'; std::cout << f() << '\n'; } int main() { test_nonconst( bind(increment, 0) ); // 1 2 3 test_const( bind(increment, 0) ); // compile-fail } It's as if you've written struct increment { int a1_; int operator()() { return ++a1_; } }; yourself.