问题描述
根据N3290 std :: unique_ptr
在其构造函数中接受一个删除参数。
无法在Windows中使用Visual C ++ 10.0或MinGW g ++ 4.4.1,也不能在Ubuntu中使用g ++ 4.6.1。
因此,我恐怕我的理解它是不完全或错误的,我不能看到一个删除者的论点,显然被忽略的点,所以任何人都可以提供一个工作实例?
参见如何工作 unique_ptr< Base> p = unique_ptr< Derived>(new Derived)
。
可能用标准的一些措辞来备份示例,
这适用于我在MSVC10
int x = 5;
auto del = [](int * p){std :: cout< 删除x,值是:< * p; };
std :: unique_ptr< int,decltype(del)> px(& x,del);
在gcc 4.5上,
我会跳过标准,除非你不认为这个例子正是你想做的。 / p>
According to N3290 std::unique_ptr
accepts a deleter argument in its constructor.
However, I can't get that to work with Visual C++ 10.0 or MinGW g++ 4.4.1 in Windows, nor with g++ 4.6.1 in Ubuntu.
I therefore fear that my understanding of it is incomplete or wrong, I can't see the point of a deleter argument that's apparently ignored, so can anyone provide a working example?
Preferably I'd like to see also how that works for unique_ptr<Base> p = unique_ptr<Derived>( new Derived )
.
Possibly with some wording from the standard to back up the example, i.e. that with whatever compiler you're using, it actually does what it's supposed to do?
This works for me in MSVC10
int x = 5;
auto del = [](int * p) { std::cout << "Deleting x, value is : " << *p; };
std::unique_ptr<int, decltype(del)> px(&x, del);
And on gcc 4.5, here
I'll skip going to the standard, unless you don't think that example is doing exactly what you'd expect it to do.
这篇关于那么,std :: unique_ptr的自定义删除程序如何工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!