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 function to pointer example

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


typedef unsigned int UINT;


class Window

{

public:

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

UINT GetID() const { return mID; }


private:

UINT mID;

};


void ShowWindowUnary(const Window& win);

int main()
{

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

list<Window> winList;

UINT winID;


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

pWin = new Window(winID);

winList.push_back(*pWin);

}

pWin = 0;


//  Show  each  window  in  the  list  -  these  are  ok.
cout << "ShowWindowUnary():\n";

for_each(winList.begin(), winList.end(), ShowWindowUnary);
cout << "\nPointer to ShowWindowUnary()\n";

for_each(winList.begin(), winList.end(), &ShowWindowUnary);

return 0;

}


void ShowWindowUnary(const Window& win)
{

cout << "Showing window " << win.GetID() << ".\n";

}


 
Privacy Policy | About Us