On Thursday 25 April 2002 12:48 pm, Lars Gullik Bjønnes wrote: > Angus Leeming <[EMAIL PROTECTED]> writes: > >> class Foo { > >> class Functor {}; > >> > >> void do_stuff() { > >> find_if(..., Functor()); > >> } > >> }; > | > | I'm hazy about why not. Because it can go out of scope? See, hazy! Could > | you lift my fog? > > I am not really sure, but just try it and watch your compiler...
? Works for me: #include <iostream> #include <string> #include <algorithm> using std::string; class Foo { public: class Functor { public: Functor(char cin) : c(cin) {} bool operator()(char comp) { return c == comp; } private: char c; }; void do_stuff() { string const me("Angus"); char const c = 'n'; string::const_iterator begin = me.begin(); string::const_iterator end = me.end(); string::const_iterator it = std::find_if(begin, end, Functor(c)); if (it == end) { std::cout << c << " not found" << std::endl; } else { std::cout << c << " found at pos " << it - begin << std::endl; } } }; int main() { Foo foo; foo.do_stuff(); return 0; } aleem@pneumon:aleem-> ./trial n found at pos 1