
Posted by mohammad tawfiq othman on November 04, 202 at 00:04:33:
In Reply to: Help on CTime << operator posted by Mauro Fiorentino on November 30, 200 at 01:12:53:
: Hi there,
: I defined an Activity class. This class has got an attribute
: as CTime firstStartTime.
: Now if I overload the << operator for the Activity class I got an
: error .
: If you have an idea why this happen please, replay.
: the error is :
: D:\MyProjects\ActiviProva\ActiviProva.cpp(48) : error C2679: binary '<<' : no operator defined which takes a right-hand operand of type 'class CTime' (or there is no acceptable conversion)
: Error executing cl.exe.
: ActiviProva.exe - 1 error(s), 0 warning(s)
: here you are the code : : #include : using namespace std; : //typedef unsigned int TIME; : class Aactivity : : public: : Aactivity(){}; : private: : : : : int main(int argc, char* argv[]) : Aactivity A; : } : /*****************/ :
: /*****************/
: #include "stdafx.h"
: #include
: #include
: #include
: #include
: typedef CTime TIME;
: {
: friend ostream& operator<< (ostream& os, const Aactivity& A );
: virtual ~Aactivity(){};
:
: void setFirstStartTime (TIME time) {firstStartTime=time;};
: void setLatestEndTime (TIME time) {latestEndTime=time;};
: TIME getFirstStartTime () const {return firstStartTime;};
: TIME getLatestEndTime ()const {return latestEndTime;};
:
: protected:
: TIME firstStartTime;
: TIME latestEndTime;
: };
: ostream &
: operator<< (ostream & ostr, const Aactivity & A)
: {
: ostr << "A.firstStartTime =" << A.getFirstStartTime() << endl;
: return ostr;
: }
: {
:
: cout << A << endl;
: return 0;
: thanks anyway,
: Mauro
:
Post a Follow Up: