Hello!
My professor gave me an assignment containing classes. This is what he asked:
****************
Implement class Time [...] It should provide the following operations:
- Five constructors:
- Default
- Takes hour, minute, second
- Takes hour, minute
- Takes hour
- Takes a Time object
*****************
My question is about the last constructor. Is it even possible for a constructor in a class to take an object of this same class as argument?
Here's what I tried to do:
class Time { private: int hour, minute, second; public: Time(){setTime(0,0,0);} Time(int hour, int minute, int second){setTime(hour, minute, second);} Time(int hour, int minute){setTime(hour,minute,0);} Time(int hour){setTime(hour,0,0);} Time(Time timeObject){this->hour=timeObject.getHour(); this->minute=timeObject.getMinute(); this->second=timeObject.getSecond();} void setTime(int hour, int minute, int second){ this->hour = hour; this->minute = minute; this->second = second;} int getHour(){return hour;} int getMinute(){return minute;} int getSecond(){return second;} };
I'm not sure what it is I'm doing wrong if it is possible, but this is the error I got: "error C2333: 'Time::Time' : error in function declaration; skipping function body".
Any suggestions/ideas?
Thanks! :)
Rita.