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

OMFG, NVM, sorry for this thread, I'm such an idiot...
The tutorial wasn't very clear :/

If it crashes as soon as it starts it should give an error message. If it isn't giving you an error message the ide might just be finishing the program so quickly it appears to simply open and close to you. Try putting a breaker at the return so the program will pause when it ends or run without debugging (At least thats what I do with visual studio if my program doesn't run in a loop).

Edit: lol, glad you figured it out most programming things are like that. Number of times I've figured out what was wrong while writing up the question on some forum is mind-boggling.

Edited 5 Years Ago by ChaseRLewis: n/a

This article has been dead for over six months. Start a new discussion instead.