对stl中的destroy函数做如下测试:

template<typename T>
void MyDestroy(T* pointer)
{
    pointer->~T();
    cout<<"OK"<<endl;
}

int main()
{
    //int *p=new int();        //这里是怎么实现的??
    //cout<<*p<<endl;    //输出为0
    int *p=NULL;        //必须给p复初值,否则运行时会出错
                        //若写成int *p;运行时出错
    MyDestroy(p);
}

上述中的int *p=new int(); 和pointer->~T();在C++中是怎样实现的??求路过大神解释!!!

相关文章:

  • 2021-07-11
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-05-26
  • 2021-12-28
  • 2021-05-27
  • 2021-05-12
猜你喜欢
  • 2021-09-24
  • 2021-11-14
  • 2022-12-23
  • 2021-05-16
  • 2022-12-23
  • 2022-12-23
  • 2021-07-26
相关资源
相似解决方案