Hi. On Tue, Jul 15, 2003 at 11:09:26AM -0400, Paul Dubuc wrote: > Here is a simplified example of some code that compiles and works with g++ > 2.95.3 but gives the following compiler error with g++ 3.3. Can anyone > tell me > what is wrong with this code and how to get it to work with the new compiler > (other than rewriting the loop without find_if and bind2nd)? Help would be > very > much appreciated. Thank you. > > #include <iostream> > #include <list> > #include <functional> > #include <algorithm> > > class FPB { > private: > long key; > public: > long getkey() const { return key; } > }; > > struct compareKey : > std::binary_function<const FPB, const long*, bool> > { > bool operator()(const FPB& pb, const long* key_ptr) const > { > return pb.getkey() == *key_ptr; > } > }; > > main() > { > std::list<FPB> lst; > long key = 1; > > std::list<FPB>::iterator iter( > std::find_if( > lst.begin(), > lst.end(), > std::bind2nd(compareKey(), &key) > ) > ); > if (iter != lst.end()) std::cout << "found" << std::endl; > else std::cout << "not found" << std::endl; > } [snip] > /vol/gnu/gcc/include/c++/3.3/bits/stl_function.h: In instantiation of > `std::bind > er2nd<compareKey>': > b2nd.cc:34: instantiated from here > /vol/gnu/gcc/include/c++/3.3/bits/stl_function.h:401: error: `typename > _Operation::result_type std::binder2nd<_Operation>::operator()(typename > _Operation::first_argument_type&) const [with _Operation = compareKey]' > and > `typename _Operation::result_type > std::binder2nd<_Operation>::operator()(typename > _Operation::first_argument_type&) const [with _Operation = compareKey]' > cannot be overloaded If you look at the class declaration of binder2nd in /vol/gnu/gcc/include/c++/3.3/bits/stl_function.h around line 401 you could see the problem. The problem is that (if _GLIBCPP_RESOLVE_LIB_DEFECTS is defined) the () operator of binder2nd is overloaded. These are the (simplified) prototypes: op::result_type operator() (const op::first_argument_type&) const ; op::result_type operator() ( op::first_argument_type&) const ; If you fill in the templatized typenames of your compareKey struct viz. "const FPB" for "op::first_argument_type" you'd see that the operator's prototypes are essentially the same which is forbidden, of course. If you declare struct compareKey : std::binary_function<FPB, const long*, bool> the error is gone. I suppose you'd want to remove the const modifier on "long*" also, then. Or you could try to undef'ine _GLIBCPP_RESOLVE_LIB_DEFECTS before bits/stl_function.h gets included... but that would be kinda wacky, YMMV. :-) HTH -- Claudio Bley ASCII ribbon campaign (") Debian GNU/Linux user - against HTML email X http://www.cs.uni-magdeburg.de/~bley/ & vCards / \