lundi 20 juillet 2015

Initialise const member with make_shared

The following code compiles using Xcode 6.3.2 but not Visual Studio 2013.

#include <cstdint>
#include <memory>

class Y
{
public:
    Y(uint32_t i) : m_i(i)
    {
    }

private:
    uint32_t m_i;
};

class X
{
public:
    X() = default;

private:
    const uint32_t m_dimension = 2;
    const std::shared_ptr<Y> m_y = std::make_shared<Y>(m_dimension);
};

The error reported is:

error C2783: 'std::shared_ptr<_Ty> std::make_shared(_Types &&...)' : could not deduce template argument for '_Ty'

Could this be a compiler bug in Visual Studio or is there something wrong with the code?

Aucun commentaire:

Enregistrer un commentaire