Objects are not created when they should be
<p>I'm currently making a relatively small project in Qt. There are 2 <code>object</code>s and 2 <code>vector</code>s that have to be available throughout the whole program life. So to achieve that, I made 4 declarations in corresponding header files, marked them extern and defined them in <code>MainWindow.cpp</code> where i use them for the first time.<br>
However, runtime error <code>std::out_of_range</code> occurs when one of the object is being created. After long session of debugging i finally found the cause and source of error :  </p>

<p><strong>MainWindow.cpp</strong>  </p>

<pre><code>#include "task.h"  //Vectors; Works
#include "date.h" //Error
#include "db.h"  //Works

std::vector&lt;Task&gt; task_vec; //extern from task.h
std::vector&lt;Group&gt; group_vec; //extern from task.h
Date date; //extern from date.h &lt;- Error when instantinating this one
Database db; //extern from db.h

MainWindow::MainWindow(){//...}
//date and db objects are used in this file
</code></pre>

<p><strong>date.cpp</strong>  </p>

<pre><code>#include "date.h" //it has "consants.h" included in it

//..Stuff
Date::Date()
{
    //Use const int variable from "constants.h"
    year = constants::START_YEAR; //Works, START_YEAR is initialized
    year_count = constants::YEAR_COUNT //Works aswell
    Month month(m, y);
}
Month::Month(int month, int year)
{
    //Use const std::map&lt;QString, std::pair&lt;int,int&gt;&gt; from "constants.h"
    day_count = constants::MONTH_DAY_MAP_LY.at(0).second //ERROR, MONTH_DAY_MAP_LY is not initialized
}
</code></pre>

<p><strong>constants.h</strong>  </p>

<pre><code>namespace constants {
const int START_YEAR = 2016;
const int YEAR_COUNT = 83;

const QList&lt;QString&gt; MONTH { "January", "February", "March",
        "April", "May", "June", "July", "August", "September", "October", "November", "December"};

const std::map&lt;QString, std::pair&lt;int, int&gt;&gt; MONTH_DAY_MAP{
    {MONTH[0], std::make_pair(0, 31)}, {MONTH[1], std::make_pair(1, 28)}, {MONTH[2], std::make_pair(2, 31)},
    {MONTH[3], std::make_pair(3, 30)}, {MONTH[4], std::make_pair(4, 31)}, {MONTH[5], std::make_pair(5, 30)},
    {MONTH[6], std::make_pair(6, 31)}, {MONTH[7], std::make_pair(7, 31)}, {MONTH[8], std::make_pair(8, 30)},
    {MONTH[9], std::make_pair(9, 31)}, {MONTH[10], std::make_pair(10, 30)}, {MONTH[11], std::make_pair(11, 31)}
};
const std::map&lt;QString, std::pair&lt;int, int&gt;&gt; MONTH_DAY_MAP_LY {
    {MONTH[0], std::make_pair(0, 31)}, {MONTH[1], std::make_pair(1, 29)}, {MONTH[2], std::make_pair(2, 31)},
    {MONTH[3], std::make_pair(3, 30)}, {MONTH[4], std::make_pair(4, 31)}, {MONTH[5], std::make_pair(5, 30)},
    {MONTH[6], std::make_pair(6, 31)}, {MONTH[7], std::make_pair(7, 31)}, {MONTH[8], std::make_pair(8, 30)},
    {MONTH[9], std::make_pair(9, 31)}, {MONTH[10], std::make_pair(10, 30)}, {MONTH[11], std::make_pair(11, 31)}
};
}
</code></pre>

<p>I have no idea why. If the <code>START_YEAR</code> and <code>YEAR_COUNT</code> are initialized, then the rest of the header should be aswell, right?<br>
Here's where i declare extern object:    </p>

<p><strong>date.h</strong>  </p>

<pre><code>//...Stuff
class Date
{
public:
    Date();

    Year&amp; operator[](int);

private:
    std::array&lt;Year, constants::YEAR_COUNT&gt; date_arr;
} extern date;
</code></pre>