【发布时间】:2014-06-23 09:02:00
【问题描述】:
在VC++ 2013的C++头文件memory中,我发现类unique_ptr的定义如下:
template<class _Ty, class _Dx> // = default_delete<_Ty>
class unique_ptr
{
...
};
让我困惑的是:模板参数没有默认类型,这是 C++11 标准所要求的。 (见here)
但是,我可以编译以下代码而不会出现任何警告或错误:
#include <memory>
using namespace std;
int main()
{
unique_ptr<int>(new int); // Should be OK! ???
// rather than unique_ptr<int, default_delete<int>>(new int);
}
为什么?
【问题讨论】:
标签: c++ templates visual-c++ c++11 unique-ptr