是C ++中删除操作符所需的正确类型吗? [英] Is the correct type required for the delete operator in C++?

查看:133
本文介绍了是C ++中删除操作符所需的正确类型吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

void * intptr = new int;
delete (int *) intptr;

(int *)需要吗?

推荐答案

是的。

是新的。唯一不需要匹配的时间是通过基本指针删除派生类型,其中基本类型有一个虚拟析构函数。

The type must match that which was new'd. The only time it doesn't have to match is deletion of a derived type through a base pointer, where the base type has a virtual destructor.

这篇关于是C ++中删除操作符所需的正确类型吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆