pickzy.com

C  |  C++  |  Objective-C  |  VC++  |  Win32  |  MFC  |  Java  |  Php  |  Delphi  |  Visual Basic  |  .Net  |  Networking  |  General  |  Games  |  Jobs  |  Javascript  |  




Menu

pickSourcecode.com


        

 




 

Cpp > Programs

 

cpp Window , list, for_each, functional tutorials

#include <iostream>
#include <list>
#include <functional>
#include <algorithm>
using namespace std;


typedef unsigned int UINT;


class Window

{

public:

Window(UINT newID = 0): mID(newID) {}


void Show() const
{

cout << "Showing window " << mID << "\n";

}


//
//  MSVC++  5  version
//
// int  Show()
// {  
// cout  <<  "Showing  window  "  <<  mID  <<  "\n";  
// return  0;
// }

private:

UINT mID;

};


int main()
{

//  create  and  add  elements  to  a  list  of  pointers  to  Window  objects
Window* pWin;

list<Window*> winPtrList;


for (UINT winID = 0; winID < 5; ++winID)
{

pWin = new Window(winID);

winPtrList.push_back(pWin);

}

pWin = 0;


//  show  each  window  in  the  list
for_each(winPtrList.begin(), winPtrList.end(), mem_fun(&Window::Show));

return 0;

}


 
Privacy Policy | About Us