std::any::~any

来自cppreference.com
< cpp‎ | utility‎ | any
 
 
 
 
~any();
(C++17 起)

若存在则销毁所含对象,如同通过调用 reset()() 进行。

示例

#include <any>
#include <cstdio>
 
struct X
{
    X() { std::puts("X::X()"); }
    X(const X&) { std::puts("X::X(const X&)"); }
    ~X() { std::puts("X::~X()"); }
};
 
int main()
{
    std::any a{X{}};
    std::puts("Leaving main()...");
}

输出:

X::X()
X::X(const X&)
X::~X()
Leaving main()...
X::~X()

参阅

销毁所含对象
(公开成员函数)