13.07.2015 Views

29 The Power of Inheritance and Polymorphism

29 The Power of Inheritance and Polymorphism

29 The Power of Inheritance and Polymorphism

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Implementation: Windows classes 1043}return sWindowRep;WindowRep *WindowRep::sWindowRep = NULL;<strong>The</strong> first time that it is called, function Instance() creates the WindowRep object;subsequent calls always return a pointer to the same object.<strong>The</strong> constructor calls function Initialize() which performs any systemdependent device initialization. It then sets up the image array, <strong>and</strong> clears thescreen.WindowRep::WindowRep(){Initialize();for(int row = 0; row < CG_HEIGHT; row++)for(int col = 0; col< CG_WIDTH; col++)fImage[row][col] = ' ';Clear();}<strong>The</strong> implementation <strong>of</strong> functions like Initialize() involves the same systemdependent calls as outlined in the "Cursor Graphics" examples in Chapter 12.Some example functions are:void WindowRep::Initialize(){#if defined(SYMANTEC)/*Have to change the "mode" for the 'console' screen.Putting it in C_CBREAK allows characters to be read one byone as they are typed*/csetmode(C_CBREAK, stdin);#else/*No special initializations are needed for Borl<strong>and</strong> IDE*/#endif}void WindowRep::MoveCursor(int x, int y){if((xCG_WIDTH)) return;if((yCG_HEIGHT)) return;#if defined(SYMANTEC)cgotoxy(x,y,stdout);#elsegotoxy(x,y);#endif}void WindowRep::PutCharacter(char ch){

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!