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; } 

Closed due to the fact that off-topic participants Abyx , sercxjo , Pavel Mayorov , Denis , pavel 7 Sep '16 at 15:40 .

It seems that this question does not correspond to the subject of the site. Those who voted to close it indicated the following reasons:

  • "The question is caused by a problem that is no longer reproduced or typed . Although similar questions may be relevant on this site, solving this question is unlikely to help future visitors. You can usually avoid similar questions by writing and researching a minimum program to reproduce the problem before publishing the question. " - Pavel Mayorov, pavel
  • “Questions asking for help with debugging (“ why does this code not work? ”) Should include the desired behavior, a specific problem or error, and a minimum code for playing it right in the question . Questions without an explicit description of the problem are useless for other visitors. See How to create minimal, self-sufficient and reproducible example . " - Abyx, sercxjo, Denis
If the question can be reformulated according to the rules set out in the certificate , edit it .

  • And which line is wrong? And give the error message completely, there must be something else on the idea. - VladD
  • @Vadim Time time = new Time (); try it - Vladislav Kuznetsov
  • @Bangerok: It will not compile, it's not Java. - VladD
  • @VladD is also possible here. We are waiting for a response from the author. - Vladislav Kuznetsov
  • @Bangerok, no, that’s not right. You can do this: Time *time = new Time(); , only then instead of a point there will be an arrow. - maestro

1 answer 1

print function, it is at least https://ideone.com/tuj5pZ

 int main() { Time time; time.setHours(12); time.setMinutes(42); time.setSeconds(54); time.print(); //<------ return 0; } 
  • What is wrong with print. Explain, please. - Vladislav Kuznetsov
  • 2
    void Time :: print () {cout << hours << ":" << minutes << ":" << seconds; } So right: time.print (); - Valera Kvip