|
Boost Users : |
From: Duane Murphy (duanemurphy_at_[hidden])
Date: 2002-09-02 13:15:36
--- At Mon, 2 Sep 2002 18:48:08 +0100, 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!)
This seems like a simple ambiguity problem more than overload resolution,
although overload resolution seems to play a part. All bind() gets is the
address of a function. If there are more than one function with the same
name, then AFAIK, there's no syntax for saying which function to use.
The solution that I have used is to not overload, or to have a function
that is not overloaded that calls the overloaded function, or to have a
free function that calls the overloaded function.
If there is a syntax for this situation, I would love to know what it is.
>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;
>}
...Duane
-- "If tyranny and oppression come to this land, it will be in the guise of fighting a foreign enemy." - James Madison
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