Boost logo

Boost Users :

From: Greg Hawkins (yg-boost-users_at_[hidden])
Date: 2002-09-02 15:32:43


You need to supply the disambiguation yourself with an explicit cast:

boost::bind((bool (part::*)(int))&part::is, _1, x)

or

boost::bind((bool (part::*)(std::string))&part::is, _1, x)

Haven't tried it on Borland though...

best,
Greg

Alex Henderson wrote:
> Hi,
>
> I'd like boost::bind to use overloaded member functions, but get an
> internal compiler error. Does bind support overload resolution, or is
> my compiler at fault? (...or more likely the code!)
>
> system = C++Builder 5 (patched), Win2k, boost_1_28_0
> example (simplified) code below
>
> Thanks,
> Alex
> //--------------------------------------------------------------------
> -------
>
> #include <string>
> #include <vector>
> #include <iostream>
> #include <boost/bind.hpp>
>
> //--------------------------------------------------------------------
> -------
>
> struct part
> {
> std::string name;
> int id;
> part(std::string name, int id) : name(name), id(id) {}
> bool is(int test) { return id == test; }
> // bool is(std::string test) { return name == test; } // uncomment
> for error };
> //--------------------------------------------------------------------
> -------
>
> int main()
> {
> int x = 6; // swap comments here for error //
> std::string x("handle"); // swap comments here for error
>
> std::vector<part> parts;
> part a("top", 3); parts.push_back(a);
> part b("spout", 6); parts.push_back(b);
> part c("handle", 9); parts.push_back(c);
>
> std::vector<part>::iterator it =
> std::find_if(parts.begin(), parts.end(), boost::bind(&part::is,
> _1,
> x));
>
> std::cout << it->name << std::endl;
>
> return 0;
> }
> //--------------------------------------------------------------------
> -------
>
>
>


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