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.

<strong>Inheritance</strong> <strong>and</strong> <strong>Polymorphism</strong> 1046}}WindowRep::Instance()->PutCharacter(ch, x + fX, y + fY);x--;y--;fCurrentImg[y][x] = ch;Note the call to WindowRep::Instance(). This returns a WindowRep* pointer.<strong>The</strong> WindowRep referenced by this pointer is then asked to output the character atthe specified point as <strong>of</strong>fset by the origin <strong>of</strong> this window.Function SetBkgd() simply validates the coordinate arguments <strong>and</strong> then sets acharacter in the background array. Function Get() returns the character at aparticular point in either background <strong>of</strong> foreground array (an example <strong>of</strong> its use isin the statement Get(x, y, fBkgd) in Window::Clear()).char Window::Get(int x, int y, char **img) const{x--;y--;return img[y][x];}Function PrepareContent() loads the current image array from the background<strong>and</strong>, if appropriate, calls SetFrame() to add a frame.void Window::PrepareContent(){for(int row = 0; row < fHeight; row++)for(int col = 0; col < fWidth; col++)fCurrentImg[row][col] = fBkgd[row][col];if(fFramed)SetFrame();}void Window::SetFrame(){for(int x=1; x

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

Saved successfully!

Ooh no, something went wrong!