Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #ifndef TEMPS_H
- #define TEMPS_H
- #include <iostream>
- class temps
- {
- private:
- int m_heures1;
- int m_heures2;
- public:
- temps(int h1, int h2);
- temps operator+(temps const &obj);
- void print();
- friend temps operator+(temps const& c1, temps const& c2);
- };
- #endif // TEMPS_H
- #include "temps.h"
- temps::temps(int h1 = 0, int h2 = 0)
- {
- m_heures1 = h1;
- m_heures2 = h2;
- }
- temps temps::operator+(const temps &obj)
- {
- temps resultat;
- resultat.m_heures1 = m_heures1 + obj.m_heures1;
- resultat.m_heures2 = m_heures2 + obj.m_heures2;
- return resultat;
- }
- void temps::print()
- {
- std::cout << m_heures1 << " + " << m_heures2 << std::endl;
- }
- temps operator+(temps const& c1, temps const& c2)
- {
- return temps(c1.m_heures1 + c2.m_heures2);
- }
- #include <iostream>
- #include "temps.h"
- using namespace std;
- int main()
- {
- temps t1(10, 5), t2(2, 4);
- temps t3 = t1 +t2;
- t3.print();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement