From dfd3da2cc461a6c77d80074b6088e9b0eed459a2 Mon Sep 17 00:00:00 2001
From: Peter Dimov Inappropriate use of
bind<R>(f, ...)
Binding a nonstandard function
+ Binding an overloaded function
const in signatures
MSVC specific: using
boost::bind;
@@ -553,6 +554,37 @@ int main()
recognized by the short form of bind.
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: