std::unique_ptr::get_deleter
性病::独特[医]PTR::[医]德莱特
Deleter& get_deleter( | | (since C++11) |
---|---|---|
const Deleter& get_deleter() const; | | (since C++11) |
返回删除对象,该对象将用于销毁托管对象。
参数
%280%29
返回值
存储的删除对象。
例外
noexcept
规格:
noexcept
例
二次
#include <iostream>
#include <memory>
struct Foo
{
Foo() { std::cout << "Foo...\n"; }
~Foo() { std::cout << "~Foo...\n"; }
};
struct D
{
void bar() { std::cout << "Call deleter D::bar()...\n"; }
void operator()(Foo* p) const
{
std::cout << "Call delete for Foo object...\n";
delete p;
}
};
int main()
{
std::unique_ptr<Foo, D> up(new Foo(), D()
D& del = up.get_deleter(
del.bar(
}
二次
产出:
二次
Foo...
Call deleter D::bar()...
Call delete for Foo object...
~Foo...
二次
© cppreference.com
在CreativeCommonsAttribution下授权-ShareAlike未移植许可v3.0。
http://en.cppreference.com/w/cpp/Memory/UNIQUE[医]PTR/GET[医]德莱特