Sorry if this might be a stupid question, I'm still new, I've been doing C++ for 3 days so far and I just reached objects..
Anyway. I made one thing to additionate seconds with seconds, minutes with minutes and hours with hours. The thing compiles but crashes as soon as the console starts and I don't know the reason.
Anyway, here is my code.
main.cpp
#include <iostream>
#include "Duree.h"
using namespace std;
int main()
{
Duree duree1(0, 10, 5), duree2(0, 15, 2);
Duree resultat;
resultat = duree1 + duree2;
duree1.show();
duree2.show();
resultat.show();
return 0;
}
Duree.cpp
#include "Duree.h"
using namespace std;
Duree operator+(Duree const& a, Duree const& b)
{
Duree resultat;
resultat = a + b;
return resultat;
}
Duree::Duree(int heures, int minutes, int secondes) : m_heures(heures), m_minutes(minutes), m_secondes(secondes)
{
if(m_secondes >= 60)
{
m_minutes += m_secondes / 60;
m_secondes %= 60;
}
if(m_minutes >= 60)
{
m_heures += m_minutes / 60;
m_minutes %= 60;
}
}
void Duree::show()
{
cout <<m_heures <<":" <<m_minutes <<":" <<m_secondes <<endl;
}
Duree.h
#ifndef DUREE_H_INCLUDED
#define DUREE_H_INCLUDED
#include <iostream>
class Duree
{
public:
Duree(int heures = 0, int minutes = 0, int secondes = 0);
void show();
private:
int m_heures;
int m_minutes;
int m_secondes;
};
Duree operator+(Duree const& a, Duree const& b);
#endif // DUREE_H_INCLUDED