diff --git a/bind.html b/bind.html index f60cab0..74110c5 100644 --- a/bind.html +++ b/bind.html @@ -60,6 +60,7 @@
See also "__stdcall" and "pascal" Support.
+An attempt to bind an overloaded function usually results in an error, as there + is no way to tell which overload was meant to be bound. This is a common + problem with member functions with two overloads, const and non-const, as in + this simplified example:
+struct X +{ + int& get(); + int const& get() const; +}; + +int main() +{ + boost::bind( &X::get, _1 ); +} ++
The ambiguity can be resolved manually by casting the (member) function pointer + to the desired type:
+int main() +{ + boost::bind( static_cast< int const& (X::*) () const >( &X::get ), _1 ); +} ++
Another, arguably more readable, alternative is to introduce a temporary + variable:
+int main() +{ + int const& (X::*get) () const = &X::get; + boost::bind( get, _1 ); +} +
Some compilers, including MSVC 6.0 and Borland C++ 5.5.1, have problems with the top-level const in function signatures: