반응형

#include <memory>
#include <vector>
#include <list>
#include <Windows.h>
#include <string.h>
#include<iostream>
#include <algorithm>

using namespace std;

 


class node{
private :

 int m_data;

public :
 int getData(){ return m_data; }
 
 node(){
  int templ=30;
  int ddd;
 }
 node(int data){

  m_data=data;
 }
 ~node(){

 }
 bool operator()(node* nodeData){
  if( nodeData->getData() == 30 )
   return true;
  else
   return false;
 }
 void print(){
  cout<<m_data<<"\t";
 }
};

int main(){


 vector<node*> nodes;

 node* pNode=NULL;
 for(int i=0;i<10;++i){
  nodes.push_back(new  node(i*10));
 }

 // mem_fun은 클래스의 멤버 함수를 함수 객체로 만든다.  : 함수객체는 타입이 될 수 있어 조건자로 들어 갈 수 있다
 // mem_fun_ref 는 객체를 넘길때 & 로 넘기는 방식이다
 for_each( nodes.begin(),nodes.end(), mem_fun( &node::print ) );  //http://www.winapi.co.kr/clec/cpp4/38-2-5.htm

 cout<<(*find_if( nodes.begin(),nodes.end(), node() ))->getData()<<endl;

 vector<node*>::iterator it=nodes.begin();
 for(;it!=nodes.end();++it){
  delete (*it);
 }
 nodes.clear();

 return 0;
}

반응형

+ Recent posts