To make your function work using const references the function CDate::convert() has to be const ( as it should to be const correct )
e.g.
KurtCode:int CDate::convert() const {
....
}
Printable View
To make your function work using const references the function CDate::convert() has to be const ( as it should to be const correct )
e.g.
KurtCode:int CDate::convert() const {
....
}
Perhaps the attached code files will help...
The class should be declared like this to be const correct .
KurtCode:class CDate
{
public:
CDate();
int setMonth();
int setDay();
int setYear();
int dayOfWeek() const;
int convert() const;
int nextDay()const;
bool isLeapYear() const;
bool isWeekDay() const;
void nameOfDay() const;
void showDate() const;
private:
int m_month,
m_day,
m_year;
int m_convert;
};
Yes, your problem lies in that the convert function is not const. However, convert also modified class data, so it cannot be const. Thus you have a little problem.
I believe you should look over your implentation. Find a way to make convert const (ie make sure it doesn't modify class data).
Otherwise you can't pass your arguments by const. And if you can't, then that means the function that takes those values can modify them, even though it shouldn't.
Look over your implentation. Learn what a class is and what it should do. A class is an object - like a car. It hides its implentation to the outside and provides access to its functions. But I don't think I can agree that it should store a converted result of its date when you call convert.