Use mem_fun_ref to pass in a user-defined member function : mem_fun_ref « STL Algorithms Helper « C++

Home
C++
1.Bitset
2.Class
3.Console
4.Data Structure
5.Data Type
6.Deque
7.Development
8.File
9.Function
10.Generic
11.Language
12.List
13.Map Multimap
14.Overload
15.Pointer
16.Qt
17.Queue Stack
18.Set Multiset
19.STL Algorithms Binary search
20.STL Algorithms Heap
21.STL Algorithms Helper
22.STL Algorithms Iterator
23.STL Algorithms Merge
24.STL Algorithms Min Max
25.STL Algorithms Modifying sequence operations
26.STL Algorithms Non modifying sequence operations
27.STL Algorithms Sorting
28.STL Basics
29.String
30.Valarray
31.Vector
C / ANSI-C
C Tutorial
C++ Tutorial
Visual C++ .NET
C++ » STL Algorithms Helper » mem_fun_refScreenshots 
Use mem_fun_ref to pass in a user-defined member function
  
#include <algorithm>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <string>
#include <vector>

using namespace std;

class PC
{
   public:
   enum part keyboard, mouse, monitor };

   PCpart a_part = PC::keyboard, int id = );
   bool operator<const PC& rhs const;

   void print() const;

   private:
   part part_;
   int id_;
};

inline
PC::PCpart a_part, int id : part_a_part ), id_id ){}

inline bool PC::operator<const PC& rhs const{  
   return id_ < rhs.id_; 
}

void PC::print() const {
   string component;
   ifpart_ == keyboard )
      component = "keyboard";
   else ifpart_ == mouse )
      component = "mouse";
   else
      component = "monitor";

   cout << "ID: " << setw<< left << id_ << " PC: " << component << endl;
}

int main( )
{
   list<PC> listA;
   listA.push_backPCPC::keyboard, ) );
   listA.push_backPCPC::mouse, ) );
   listA.push_backPCPC::monitor, ) );
   listA.push_backPCPC::keyboard, ) );
   listA.push_backPCPC::monitor, ) );

   for_eachlistA.begin(), listA.end(),mem_fun_ref&PC::print ) );
}
  
    
  
Related examples in the same category
1.mem_fun_ref with method from user-defined class
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.