|
Boost Users : |
From: Peter Dimov (pdimov_at_[hidden])
Date: 2004-10-15 12:26:21
Schalk_Cronje_at_[hidden] wrote:
>> I wonder why gcc is able to compile it. :-)
>
> Well considering that the following also yields different results on
> MSVC7.1 and gcc 3.2/3.3 I would wonder if there is a problem with one
> of the compilers
>
> #include <iostream>
> #include <boost/bind.hpp>
>
> struct X
> {
> void f() {std::cout << "None" << std::endl;}
> void f() const {std::cout << "const" << std::endl;}
> };
[...]
> int main()
> {
> X x;
> boost::bind(&X::f, _1)(x);
> }
&X::f is ambiguous in boost::bind(&X::f, _1). boost::bind can't figure out
which one you want, so it picks one at random. The example is actually
similar to the one below; your "run" overloads accept an object and can be
ordered, but the bind expression does not. boost::mem_fn(&X::f) is similarly
ambiguous.
#include <iostream>
struct X
{
void f() {}
void f() const {}
};
template <class T> void mem_fn( void (T::*f_)() )
{
std::cout << "None" << std::endl;
}
template <class T> void mem_fn( void (T::*f_)() const )
{
std::cout << "const" << std::endl;
}
int main()
{
mem_fn(&X::f);
}
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