(destructor)
描述 (Description)
C ++析构函数std::set::~set()破坏了set容器。 这可确保释放已使用的存储。
注意:如果元素是指针,则不会销毁指向的对象。 它只确保所有迭代器,指针和引用都无效。
声明 (Declaration)
以下是std :: set :: ~set()析构函数在各种C ++版本中的工作方式。
C++98
~set() destroys all set container elements, and deallocates all the
storage capacity allocated by the container using its allocator.
C++11
~set() calls <i>allocator_traits::destroy</i> on each of the contained
elements, and deallocates all the storage capacity allocated by the
set container using its allocator.
C++14
~set() calls <i>allocator_traits::destroy</i> on each of the contained
elements, and deallocates all the storage capacity allocated by the
set container using its allocator.
返回值
析构函数永远不会返回任何值。
异常 (Exceptions)
如果抛出任何异常,此成员函数不起作用。
时间复杂
容器的线性大小,即O(N)
例子 (Example)
以下示例显示了std :: set :: ~set()析构函数的用法。
#include <iostream>
#include <set>
#include <string>
using namespace std;
int main(void) {
//Default constructor
std::set<string> t_set;
t_set.insert("IOWIKI");
return 0;
}
上述程序将正确编译和执行。
它从main()返回的那一刻; 将调用析构函数~set()来销毁集合容器't_set'