Sunday, October 30, 2005

reporting change of state of a class

The function calls another method when the state of a class changes

 

 

#include <iostream>

 

 

class C

   {

    public:

      C() {state = 0;}

      void draw();

      void change_state() { state = 1;}

      void draw1() {std::cout << "draw1 called\n";}

      void draw2() {std::cout << "draw2 called\n";}

    private:

      int state;

      };

//---------------------

void C::draw()

   {

    if (state == 0)

      draw1();

    else

       draw2();

       }

//=================

int main()

   {

    C c;

    c.draw1();

    c.change_state();

    c.draw();

 

 

    std::cin.get();

    }

 

 

 

Pradyut
http://pradyut.tk
http://spaces.msn.com/members/oop-edge/
http://groups-beta.google.com/group/oop_programming
India

 

No comments: