I have searched the forum and googled, but I can't get this code to compile (using VS2010 and gcc4.6.1):
VS2010 presents an error message likeCode:#include <string> #include <vector> #include <algorithm> #include <boost/bind.hpp> class X { public: void foo( const std::vector<std::string>& v ) { std::for_each( v.begin(), v.end(), std::bind1st( std::mem_fun(&X::bar), this ) ); } private: void bar( const std::string& s ) const { } };
"member function already defined or declared"
and gcc something like "... function can not be overloaded" (very cryptic error message).
If I change the vector to foo to std::vector<int> and let bar() take an int, it works perfectly fine.
And if I use boost
the above code compiles as well.Code:std::for_each( v.begin(), v.end(), boost::bind( std::mem_fun(&X::bar), this, _1 ) );
While it is perfectly fine for me to use boost I would nevertheless like to understand what's happening here. I have spent more than an hour with this.
Could someone explain what is the problem here?
Thanks,
Richard




Reply With Quote
