home *** CD-ROM | disk | FTP | other *** search
/ Microsoftware Monthly 19…2 Programming Power Tools / MASO9512.ISO / cpptutor / cpptutor.arj / EXAMPLES / EX1316.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1993-10-26  |  701 b   |  25 lines

  1. // \EXAMPLES\EX1316.CPP
  2.  
  3. #include <iostream.h>
  4.  
  5. class base1 {
  6.    int i;
  7. public:
  8.    base1(int j = 3) : i(j) { }   // constructor for base class
  9.    int geti() { return i; }      // function returns value of i
  10. };
  11.  
  12. class derived1 : public base1 {  // derived1 derived from base1
  13. public:
  14.    int geti() { return 0; }      // override of geti() in base1
  15.    void printi() { cout << "Here is i " << geti() << endl; }
  16. };
  17.  
  18. void main() {
  19.    derived1 d;                   // define an object of derived1
  20.    cout << "Here is i " << d.geti() << endl; // call base1 member
  21.                                  // from object of derived1
  22.    d.printi();                   // call derived1 member
  23. }
  24.  
  25.