It seems to be a simple task, but it gives an error:
non-standard syntax; use '&' to create a pointer to member.
How to deal with it?
Code:
#include <iostream> #include <windows.h> using namespace std; class Time { private: int hours, minutes, seconds; public: Time(); Time(int, int, int); int getHours()const; int getMinutes()const; int getSeconds()const; void setHours(int); void setMinutes(int); void setSeconds(int); void set(int, int, int); void print(); }; Time::Time(int hours, int minutes, int seconds) { set(hours, minutes, seconds); } Time::Time() { hours = 0; minutes = 0; seconds = 0; } void Time::setHours(int hours) { if (hours > -1 && hours < 24) this->hours = hours; else this->hours = 0; } int Time::getHours()const { return hours; } void Time::setMinutes(int mminutes) { if (mminutes > -1 && mminutes < 60) this->minutes = mminutes; else this->minutes = 0; } int Time::getMinutes()const { return minutes; } void Time::setSeconds(int seconds) { if (seconds > -1 && seconds < 60) this->seconds = seconds; else this->seconds = 0; } int Time::getSeconds()const { return seconds; } void Time::set(int hours, int minutes, int seconds) { setHours(hours); setMinutes(minutes); setSeconds(seconds); } void Time::print() { cout << hours << ":" << minutes << ":" << seconds; } int main() { srand(GetTickCount()); Time time; time.setHours(12); time.setMinutes(42); time.setSeconds(54); time.print; return 0; }
Time *time = new Time();, only then instead of a point there will be an arrow. - maestro