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; }
g++ -v b2nd.cc Reading specs from /vol/gnu/gcc/bin/../lib/gcc-lib/sparc-sun-solaris2.8/3.3/spec s Configured with: ../gcc-3.3/configure --prefix=/vol/gnu/gcc-3.3 --enable-shared --enable-threads --enable-cpp --enable-languages=c++ --with-gnu-as --with-as=/vo l/gnu/gcc-3.3/bin/as --with-gnu-ld --with-ld=/vol/gnu/gcc-3.3/bin/ld --host=spar c-sun-solaris2.8 Thread model: posix gcc version 3.3 /vol/gnu/gcc/bin/../lib/gcc-lib/sparc-sun-solaris2.8/3.3/cc1plus -quiet -v -ipr efix /vol/gnu/gcc/bin/../lib/gcc-lib/sparc-sun-solaris2.8/3.3/ -D__GNUC__=3 -D__ GNUC_MINOR__=3 -D__GNUC_PATCHLEVEL__=0 -Dsparc -D__sparc__ -D__sparc -D__GCC_NEW _VARARGS__ -Acpu=sparc -Amachine=sparc b2nd.cc -D__GNUG__=3 -quiet -dumpbase b2n d.cc -auxbase b2nd -version -o /tmp/ccUGtNRa.s GNU C++ version 3.3 (sparc-sun-solaris2.8) compiled by GNU C version 3.3. GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072 ignoring nonexistent directory "/vol/gnu/gcc/sparc-sun-solaris2.8/include" ignoring nonexistent directory "/usr/local/include" ignoring nonexistent directory "/vol/gnu/gcc-3.3/sparc-sun-solaris2.8/include" ignoring duplicate directory "/vol/gnu/gcc-3.3/include/c++/3.3" ignoring duplicate directory "/vol/gnu/gcc-3.3/include/c++/3.3/sparc-sun-solaris 2.8" ignoring duplicate directory "/vol/gnu/gcc-3.3/include/c++/3.3/backward" ignoring duplicate directory "/vol/gnu/gcc-3.3/lib/gcc-lib/sparc-sun-solaris2.8/ 3.3/include" #include "..." search starts here: #include <...> search starts here: /vol/gnu/gcc/include/c++/3.3 /vol/gnu/gcc/include/c++/3.3/sparc-sun-solaris2.8 /vol/gnu/gcc/include/c++/3.3/backward /vol/gnu/gcc/lib/gcc-lib/sparc-sun-solaris2.8/3.3/include /vol/gnu/gcc-3.3/include /usr/include End of search list. /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
-- Paul M. Dubuc mailto:pdubuc@xxxxxxx Room 4349B (614) 447-3600 x2692 http://www.purl.org/dubuc/cas/