Boost logo

Boost :

From: Terje Slettebø (tslettebo_at_[hidden])
Date: 2003-05-03 09:24:44


>From: "Peter Dimov" <pdimov_at_[hidden]>

> Terence Wilson wrote:
> > I have the following code:
> >
> > int val
> > std::vector<std::string> ThingVec;
> > std::for_each(ThingVec.begin(), ThingVec.end(), boost::bind(foo, val,
> > _1));
> >
> > When foo has no overloads it compiles, otherwise I get a raft of
> > compile errors from VC++ .Net 2003. Is there a way to explicity state
> > the
> > correct overload? Can bind handle overloaded functions?
>
> C++ can't handle overloaded functions in such contexts. You can
disambiguate
> by taking the address of the function first:
>
> void (*pf)(std::string) = &foo;
>
> or by using a cast:
>
> (void (*)(std::string))&foo

Gabriel Dos Reis had a proposal for language change regarding this, in his
presentation at the ACCU conference 2003. The paper is here
(http://www-sop.inria.fr/galaad/personnel/gdr/C++/talks/type-of-toupper.pdf)
. The proposal is essentially to allow the overload selection to be deferred
to the point of call, where it's clear what function will be used (rather
than at the point of passing it to a function like for_each).

The paper also gives other ways of handling this.

Regards,

Terje


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