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
> 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
. 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.



Boost list run by bdawes at, gregod at, cpdaniel at, john at