2070 / C++ / Класи / Перевантаження операторів / Перевантаження оператору виводу <<

 

#include <iostream>
using namespace std;

class Date
{
    int d, m, y;

  public:
    Date(int d2, int m2, int y2)
    {
      m = m2; d = d2; y = y2;
    }
    friend ostream& operator<<(ostream& os, const Date& dt);
};

ostream& operator<<(ostream& os, const Date& dt)
{
  os << dt.d << '.' << dt.m << '.' << dt.y;
  return os;
}

int main()
{
  Date dt(25, 10, 2000);
  cout << dt;
  system("pause");
  return 0;
}

25.10.2000