Exception with shared_ptr invoking make_shared(Args...) c++
<p>I've got a weird behavior and after having spent several hours, I'm finally here.
I have a class DataModel, belonging to its Wrapper. More exactly, the Wrapper instance object has a shared_ptr of DataModel</p>

<p>Wrapper.h :</p>

<pre><code>class Wrapper 
{
    shared_ptr&lt;DataModel&gt; model;
}
</code></pre>

<p>This pointer is initialized in the constructeur with nullptr so as to be initialized after.</p>

<p>Wrapper.cpp :</p>

<pre><code>Wrapper::Wrapper(/* few args here*/) : model(nullptr) { ... }

Wrapper::init(Args...)
{
    model =  std::make_shared&lt;DataModel&gt;(Args...)
}
</code></pre>

<p>Somewhere else in a Supervising class (which contains a shared_ptr of Wrapper)</p>

<pre><code>SupervisingClass::SomeFunction()
{
    Wrapper-&gt;init();
}
</code></pre>

<p>And it throws the following exception : </p>

<p>First-chance exception at 0x000000013FB621C4 in CSGeo.exe: 0xC0000005: Access violation reading location 0x0000000000000018.
If there is a handler for this exception, the program may be safely continued.</p>

<pre><code>        MyApp.exe!std::swap&lt;std::_Ref_count_base * __ptr64&gt;(std::_Ref_count_base * &amp; _Left, std::_Ref_count_base * &amp; _Right) Line 53    C++
        MyApp.exe!std::_Ptr_base&lt;DataModel&gt;::_Swap(std::_Ptr_base&lt;DataModel&gt; &amp; _Right) Line 316 C++
        MyApp.exe!std::shared_ptr&lt;DataModel&gt;::swap(std::shared_ptr&lt;DataModel&gt; &amp; _Other) Line 662    C++
        MyApp.exe!std::shared_ptr&lt;DataModel&gt;::operator=(std::shared_ptr&lt;DataModel&gt; &amp;&amp; _Right) Line 597  C++
        MyApp.exe!Wrapper::init(const QStringList &amp; recentProjects, bool insertNewVirtualProject) Line 83   C++
        MyApp.exe!SupervisingClass::SomeFunction() Line 137 C++
</code></pre>

<p>If I try to reset my model in the init function, it crashes as well. Any idea ? 
I'm lost this time. And it's not the first time I got troubles with reset function and shared_ptr, I think there is something I miss. And why would the operator= be called, considering that the pointer isn't initialized, c++ should only call the good constructor and forwarding Args, nope ???</p>

<p>It might be relevant to add that before, the model was directly included in the Supervising class (just cut past the code), and I inserted a wrapper between them to get more code clarity with hundreds of lines. And yes, it used to work before.</p>

<p>Thanks by advance for your time</p>