Boost logo

Boost :

From: Slawomir Lisznianski (slisznia_at_[hidden])
Date: 2006-12-27 23:34:02


Given these two type declarations:

   typedef boost::function1<void, int &> signature;

   typedef void (*fp)(int &);

and these two function definitions:

   void not_match(int v) { } // arg by value

   void match(int & v) { } // arg by ref

The following seems to be true on my compiler (GCC 4.0.2):

Case 1) signature fn = match; // compiles

Case 2) signature fn = not_match; // compiles (problematic)

Case 3) fp fn = match; // compiles

Case 4) fp fn = not_match; // fails

My question is, shouldn't Boost.Function library fail in case 2 with the
error along the lines of case 4's: "error: invalid conversion from ‘void
(*)(int)’ to ‘void (*)(int&)’"?

I noticed this problem when users of my library register callbacks but
occasionally mistype their function signature. They end up modifying
function-local, rather than "out", variables.

Cheers,

-- 
Slawomir Lisznianski
Paramay Group, LLC
"Programs for Research Machinery"

Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk