I have no idea why this code should work, but tell me what to do if i want to add two objects together. please. while you are trying to answer please be more noob specific
sorry for my bad english, I am an Indian, here is my code.
#include<iostream>
using namespace std;
class time
{
private:
int sec;
int mint;
int hours;
public:
int Inputsec;
int Inputmint;
int Inputhours;
time(int Inputsec, int Inputmint, int Inputhours):sec(Inputsec), mint(Inputmint), hours(Inputhours){};
time operator+(time Inputobj)
{
time blah (sec+Inputsec,mint+Inputmint,hours+Inputhours);
return blah;
}
void DisplayCurrentTime()
{
cout << "The Current Time Is"<<endl<< hours<<" hours"<<endl<<mint<<"minutes"<<endl<<sec<<"seconds"<<endl;
}
};
int main()
{
time now(11,13,3);
time after(13,31,11);
time then(now+after);
then.DisplayCurrentTime();
}
code is working fine but it is giving me horrible output. Where is my mistake?
timealready exists inctimeheader.