在Visual C++(2008和2010)中,以下代码无法编译,并显示以下错误:
#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 ) )
{
}
};
错误C2039:“make_shared”:不是“全局命名空间”的成员
错误C3861:“make_shared”:找不到标识符
它在抱怨P :: Foo()的定义而不是:: Foo()。
有人知道为什么Foo()可以具有带std :: make_shared的默认参数,但P :: Foo()却不能吗?
shared_ptr
位于std::tr1
中,并且未实现make_shared
(make_shared
不是 TR1 的一部分)。 - James McNellis::make_shared
。 - Johannes Schaub - litbboost::shared_ptr
,但在VS2008中无法编译。它抱怨“无法推断出'T'的模板参数”,这对我来说毫无意义,因为你明确指定了T(int
)。 - James McNellis