This is the class using the Time class and where the "magic" happens. the data is taken out from a text file
while(i<flightsNumber){
if(ist>>nameArr>>arr>>airline>>fare>>time){
Flight flight(dep,arr,nameArr,airline,fare,time);
flightVector.push_back(flight);
//pre-check
cout<<flight.getTime()<<endl;
}
else
error("Error: programData.dat contains invalid data");
//post-check
cout<<flightVector[i].getTime()<<endl;
i++;
}
and this is my MyTime class
#include "MyTime.h"
MyTime::MyTime()
:h(0),m(0){
}
MyTime::MyTime(int hh,int mm)
:h(hh),m(mm){
if(hh<0 || mm<0 || mm>59)
error("Time(): invalid construction");
}
void MyTime::setTime(int hh,int mm){
if(hh<0 || mm<0 || mm>59)
error("setTime(): invalid time");
h=hh;
m=mm;
}
int MyTime::getHour() const{
return h;
}
int MyTime::getMinute() const{
return m;
}
istream& operator>>(istream& is,MyTime& time){
char ch1;
int hour,minute;
is>>hour>>ch1>>minute;
if(is){
if(ch1==':'){
time.h = hour;
time.m = minute;
}
else
is.setstate(ios_base::failbit);
}
else
is.setstate(ios_base::failbit);
return is;
}
ostream& operator<<(ostream& os,const MyTime& time){
return os<<time.h<<":"<<time.m;
}
the output is:
1:12
-33686019: -1414812757
How on earth is this possible?
the value of the instance of MyTime change right after the push_back() function is executed.