Exercise Leap: 'is_leap_year' is not a member of 'leap'

Hey guys,

I’m trying to solve the Leap exercise of the C++ track.
My idea of solving the task is to create a function that takes an integer year as input and returns a boolean depending on whether the year is or isn’t a leap year:

#include "leap.h"

namespace leap {

    bool is_leap_year(int year) {
        if (year % 4 == 0) {
            return true;
        } else if (year % 100 == 0 && year % 400 == 0) {
            return true;
        } else {
            return false;
        }
    }
}  // namespace leap

When running the test, I’m getting an error message saying that ‘is_leap_year’ is not a member of ‘leap’.

I wanted to ask for a hint if there is anything wrong with the logic of my code, or if there is anything else I need to pay attention to in order to solve this exercise (e.g. there is also a helper file included, do I need to modify anything in that file as well)?

Thank you!

Yes… but once the tests work, the tests should help flag any logic issues.

There is a header file. It ought to already exist and ought to contain the following. Did you perhaps remove it?

#if !defined(LEAP_H)
#define LEAP_H

namespace leap {

}  // namespace leap

#endif // LEAP_H

Hi Isaac,

thank your for your reply!

There is a header file. It ought to already exist and ought to contain the following. Did you perhaps remove it?

No, I haven’t removed the header file and it contains exactly what you’ve posted.

Woops. I just noticed the header file doesn’t have the is_leap_year function in it! I suppose you’d need to add it :slight_smile:

Hey Isaac,

thank you! After adding bool is_leap_year(int year); to the header file, the code could be compiled.
I was able to solve the exercise afterwards (there was still a logic error in my code though which I had to fix first;)).
Maybe as feedback for this exercise: I think it is nowhere mentioned in the concepts/exercises that the function has to be declared in the header file as well. It would help a beginner to explain this somewhere first. Thanks!

Hey there,

I am a maintainer of the c++ track and I also wrote the syllabus to make it easier for students to grasp the concept of headers. There is a concept exercises in the syllabus for headers: Headers in C++ on Exercism. Do you think it needs any additional hints so that students can better understand the mechanics?

Hi Vaeng,

I’ve just skimmed through the headers syllabus and it contains all necessary information!
I think my problem was that I thought I have to go through the concepts in the syllabus from top to bottom, so from more basic concepts to more advanced ones.
Maybe it would help to leave a hint in the if syllabus to the headers syllabus.

Thank you!