How to output x++ with operator++ in my class CTimeSpan. I create like the following example:
#include <iostream>
using namespace std;
class CTimeSpan {
private:
unsigned int day; //day
unsigned int hour;
unsigned int minute;
unsigned int second;
public:
ostream& operator<<(ostream& os,const CTimeSpan& tm)
{
os << tm.day << "d"
<< " " << tm.hour << "h"
<< " " << tm.minute << "p"
<< " " << tm.second << "s";
return os;
}
CTimeSpan CTimeSpan::operator++(int s) {
CTimeSpan temp = *this;
++* this;
return temp;
}
};
int main()
{
CTimeSpan tm1{ 1, 2, 3, 4 };
cout << tm1++; //it's error "<<"
}
*thank you very much. Help me
Aucun commentaire:
Enregistrer un commentaire