VC6 compiler limits with STL's mem_fun?
-
Hi I need a little (or big...) help with my Visual C++ 6.0 compiler because I guess I found a C++ programm using some STL functions which my compiler does not understand. Basically it's about the functions from STL called "mem_fun_ref" and "mem_fun". In short, I do not get the following little program to get compiled: /* The following code example is taken from the book * "The C++ Standard Library - A Tutorial and Reference" * by Nicolai M. Josuttis, Addison-Wesley, 1999 * * (C) Copyright Nicolai M. Josuttis 1999. * Permission to copy, use, modify, sell and distribute this software * is granted provided this copyright notice appears in all copies. * This software is provided "as is" without express or implied * warranty, and with no claim as to its suitability for any purpose. */ //#define mem_fun1 mem_fun #include #include #include #include #include class Person { private: std::string name; public: //... void print () const { std::cout << name << std::endl; } void printWithPrefix (std::string prefix) const { std::cout << prefix << name << std::endl; } }; void foo (const std::vector& coll) { using std::for_each; using std::bind2nd; using std::mem_fun_ref; // call member function print() for each element for_each (coll.begin(), coll.end(), mem_fun_ref(&Person::print)); // call member function printWithPrefix() for each element // - "person: " is passed as an argument to the member function for_each (coll.begin(), coll.end(), bind2nd(mem_fun_ref(&Person::printWithPrefix), "person: ")); } void ptrfoo (const std::vector& coll) // ^^^ pointer ! { using std::for_each; using std::bind2nd; using std::mem_fun; // call member function print() for each referred object for_each (coll.begin(), coll.end(), mem_fun(&Person::print)); // call member function printWithPrefix() for each referred object // - "person: " is passed as an argument to the member function for_each (coll.begin(), coll.end(), bind2nd(mem_fun(&Person::printWithPrefix), "person: ")); } int main() { std::vector coll(5); foo(coll); std::vector coll2; coll2.push_back(new Person); ptrfoo(coll2); } Hint: the first
-
Hi I need a little (or big...) help with my Visual C++ 6.0 compiler because I guess I found a C++ programm using some STL functions which my compiler does not understand. Basically it's about the functions from STL called "mem_fun_ref" and "mem_fun". In short, I do not get the following little program to get compiled: /* The following code example is taken from the book * "The C++ Standard Library - A Tutorial and Reference" * by Nicolai M. Josuttis, Addison-Wesley, 1999 * * (C) Copyright Nicolai M. Josuttis 1999. * Permission to copy, use, modify, sell and distribute this software * is granted provided this copyright notice appears in all copies. * This software is provided "as is" without express or implied * warranty, and with no claim as to its suitability for any purpose. */ //#define mem_fun1 mem_fun #include #include #include #include #include class Person { private: std::string name; public: //... void print () const { std::cout << name << std::endl; } void printWithPrefix (std::string prefix) const { std::cout << prefix << name << std::endl; } }; void foo (const std::vector& coll) { using std::for_each; using std::bind2nd; using std::mem_fun_ref; // call member function print() for each element for_each (coll.begin(), coll.end(), mem_fun_ref(&Person::print)); // call member function printWithPrefix() for each element // - "person: " is passed as an argument to the member function for_each (coll.begin(), coll.end(), bind2nd(mem_fun_ref(&Person::printWithPrefix), "person: ")); } void ptrfoo (const std::vector& coll) // ^^^ pointer ! { using std::for_each; using std::bind2nd; using std::mem_fun; // call member function print() for each referred object for_each (coll.begin(), coll.end(), mem_fun(&Person::print)); // call member function printWithPrefix() for each referred object // - "person: " is passed as an argument to the member function for_each (coll.begin(), coll.end(), bind2nd(mem_fun(&Person::printWithPrefix), "person: ")); } int main() { std::vector coll(5); foo(coll); std::vector coll2; coll2.push_back(new Person); ptrfoo(coll2); } Hint: the first
It compiles on VC 7.1. Kevin