I'm new in c++, and I'm writing a program that calculate if the entered year is leap or not, but this returns me an error that says: cannot overload functions distinguished by return type alone. And also, doesn't accept the operator "==" with a boolean expression. Why? Thanks. This is my code:
using namespace std;
int leap_year(int year);
bool div(int num, int divid) {
if (num % divid == 0)
return true;
else
return false;
}
int leap_year(int year) {
if (div(year, 400))
return 365;
else if (div(year, 100) & div(year, 400) == false)
return 366;
else
return 365;
}
void main() {
int year;
cout << "Year: ";
cin >> year;
int result = leap_year(year);
cout << result;
system("pause");
}
Your definition of
bool div(int num, int divid)is shadowingstd::div, because you pollute your global namespace due tousing namespace std;Remove
using namespace std;and usestd::where appropriate.