I am writing a Time class with overloaded functions and have a problem at the extraction operator. I keep getting an error which says that ostream is not a member of std and that the identifier ostream is undefined. I looked at similar problems that were solve here and tried their solution of adding "std::" and using namespace std; but I still get the error. Help solving this error will be much appreciated. I can also update this with the full code if needs be.
the relevant declaration in the header file: //Time.h file
#ifndef TIMEGUI_TIME_H
#define TIMEGUI_TIME_H
class Time
{
public:
int hour;
int minutes;
int second;
Time(int hours, int minutes, int seconds);
Time();
friend std::ostream &operator <<( std::ostream&, const Time&);
};
endif //TIMEGUI_TIME_H
//This is the relevant part of the implementation
using namespace std;
Time::Time()
{
}
Time::Time(int hours, int minutes, int seconds)
{
this->hour = hours;
this->minutes = minutes;
this->second = seconds;
}
ostream &operator<<( ostream &out, const Time &ptr ) {
out << ptr.hour<< ":" << ptr.minutes << ":" << ptr.second;
return out;
}
And this is the main so far:
#include "Time.h"
#include <iostream>
using namespace std;
int main()
{
Time t1;
return 0;
}
Aucun commentaire:
Enregistrer un commentaire