C ++ cannot overload functions distinguished by return type alone

473 Views Asked by At

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");
}
1

There are 1 best solutions below

1
Cory Kramer On

Your definition of bool div(int num, int divid) is shadowing std::div, because you pollute your global namespace due to using namespace std;

Remove using namespace std; and use std:: where appropriate.