/********************************************
 File:   04Replacement.cpp for CS319-Week 12
 What:   What happens when the base and derived
    classes have members with the same name?
    In this example, the base and derived 
    classes  both have  a function called 
    PrintData() with the same "signature".
*********************************************/

#include <iostream>

// The base class
class Point {
protected:  // this was private in 01InheritExample
  int x;
public:
  Point(int X=0) {x=X;};
  int GetX(void) {return(x);};
  void SetX(int X) {x=X;};
  void PrintData(void);
};

// The Point class has a method called "PrintData":
void Point::PrintData(void)
{
  std::cout << "(" << x << ")\n";
}


// The derivated class will inherit x, GetX
class TwoPoint : public Point {
private:
  int y;
public:      
  TwoPoint(int X=0, int Y=0) {x=X; y=Y;};
  int GetY(void) {return(y);};
  void SetY(int Y) {y=Y;};
  void PrintData(void);
};

// The TwoPoint class also has a method 
// called PrintData()
void TwoPoint::PrintData(void)
{
  std::cout << "(" << x << "," << y << ")\n";
}

int main(void)
{
  TwoPoint d;

  d.SetX(1); d.SetY(2);
  std::cout << "Calling the TwoPoint version of d.PrintData(): d=";
  d.PrintData();

  std::cout << "Calling the Point version of d.PrintData(): d=";
  d.Point::PrintData();
  return(0);
}
