Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. ATL / WTL / STL
  4. VC6 compiler limits with STL's mem_fun?

VC6 compiler limits with STL's mem_fun?

Scheduled Pinned Locked Moved ATL / WTL / STL
c++tutorialgraphicshelpquestion
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    T T H
    wrote on last edited by
    #1

    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

    K 1 Reply Last reply
    0
    • T T T H

      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

      K Offline
      K Offline
      Kevin McFarlane
      wrote on last edited by
      #2

      It compiles on VC 7.1. Kevin

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups