Let's consider time class with hh, mm as data members representing hours and minutes of a time instance, to illustrate overloading of few basic operators.

All QuestionsCategory: Cpp LanguageLet's consider time class with hh, mm as data members representing hours and minutes of a time instance, to illustrate overloading of few basic operators.
Anonymous asked 3 years ago
1 Answers
Anonymous answered 3 years ago
#include<iostream>
class MyTime {
  int hh;
  int mm;
  public:
  MyTime(int x,int y):hh(x),mm(y) { }    
  MyTime(const MyTime& ref):hh(ref.hh),mm(ref.mm){ }
  void display() {
    std::cout << hh << ":" << mm << "\n";
  }
};
int main() {
  MyTime t1(10,20);
  t1.display();
  
  MyTime t2(t1);
  t2.display();
  
  return 0;
}