std::make_shared as a default argument does not compile

Posted by Mark Bryant on Stack Overflow See other posts from Stack Overflow or by Mark Bryant
Published on 2010-05-07T13:14:53Z Indexed on 2010/05/07 13:18 UTC
Read the original article Hit count: 177

Filed under:

In Visual C++ (2008 and 2010), the following code does not compile with the following error:

#include <memory>

void Foo( std::shared_ptr< int >    test = ::std::make_shared< int >( 5 ) )
{
}

class P
{
    void
    Foo( std::shared_ptr< int > test = ::std::make_shared< int >( 5 ) )
    {
    }
};

error C2039: 'make_shared' : is not a member of '`global namespace''

error C3861: 'make_shared': identifier not found

It is complaining about the definition of P::Foo() not ::Foo().

Does anybody know why it is valid for Foo() to have a default argument with std::make_shared but not P::Foo()?

© Stack Overflow or respective owner

Related posts about c++