C++ -- Why I can return an int for class Month
<p>Saw the following code snippet and I have problems to understand how it works.</p>

<pre><code>class Month {
public:
    static const Month Jan() { return 1; }
    ...
    static const Month Dec() { return 12; }

    int asInt() const { return monthNumber; }
private:
    Month(int number) : monthNumber(number) {}
    const int monthNumber;
}
</code></pre>

<p>The class is designed in this way so that the user will not get invalid month value.</p>

<p>Here is the question:
why the static function Jan can return 1 with the return value as Month?</p>

<p>Thank you</p>

<p>Based on the comments, this class can be designed as follows:</p>

<pre><code>class Month {
public:
    static const Month Jan() { return Month(1); }
    ...
    static const Month Dec() { return Month(12); }

    int asInt() const { return monthNumber; }
private:
    explicit Month(int number) : monthNumber(number) {}
    const int monthNumber;
};
</code></pre>
