首页  >  问答  >  正文

c++ - ~int(),里边会做些什么,网上没找到资料

#include<iostream>
#include<array>

using namespace std;

template<typename T>
void des(T * pointer)
{
    pointer->~T();
}


int main()
{
    
    int * p = new int[8];
    for (int i = 0; i < 8; i++)
        *(p + i) = i;
    
    des(p + 3);
    
    for (int i = 0; i < 8; i++)
        cout << *(p + i) << endl;//0 1 2 3 4 5 6 7

    return 0;
}

这是我的测试,函数必须使用模板,如果去掉模板,以int代替T的话,根本无法运行,所以这里我想问两个问题:
(1)~int()是什么?
(2)为什么用模板就可以正确运行?

PHP中文网PHP中文网2714 天前553

全部回复(1)我来回复

  • PHP中文网

    PHP中文网2017-04-17 15:40:43

    http://stackoverflow.com/ques...

    回复
    0
  • 取消回复