在 C++ 中重载 delete [] 运算符
overloading delete [] operator with throw in c++
根据代码,它应该执行 catch 块,但为什么它不执行
如何在重载删除运算符中测试 else 运算符
提前致谢
#include<iostream>
#include<stdlib.h>
using namespace std;
void operator delete[](void *p) throw(int)
{
if (p)
{
cout << "address of p is" << p << endl;
free(p);
cout << "in deleten" << endl;
}
else
{
cout << "in throw n";
throw 5;
}
}
int main()
{
try
{
int *a = new int[20];
a = NULL;
delete[] a;
}
catch (...)
{
cout << "in catch" << endl;
}
}
运算符
重载函数中的 *p 接受地址。使用 & after delete 语句调用时发送地址。在此示例中...
#include<iostream>
#include<stdlib.h>
using namespace std;
void operator delete[](void *p = NULL) throw(int)
{
if (p)
{
cout << "address of p is" << p << endl;
free(p);
cout << "in deleten" << endl;
}
else
{
cout << "in throw n";
throw 5;
}
}
int main()
{
try
{
int *a = new int[20];
a = NULL;
delete[] &a;
}
catch (...)
{
cout << "in catch" << endl;
}
}
相关文章:
- 运算符C++ "delete []"仅删除 2 个前值
- g++用户定义的动态链接库上的全局new和delete运算符
- 体系结构x86_64的未定义符号:std:terminate(),typeinfo,运算符delete[],运算符new
- 为什么数组大小信息可用于"sizeof"运算符和 delete[] 运算符,但在将数组作为参数传递到
- 为什么 std::vector 使用 std::分配器而不是运算符 new 和 delete?
- 使用 delete [] 运算符取消分配类中数据成员的内存
- delete运算符如何处理c中的指针
- 在析构函数中调用"delete"运算符时"compiler is out of heap space"编译器错误
- 重载运算符 new 和运算符 delete 带有三个参数
- 如果我为一个类编写new和delete运算符,我是否必须编写它们的所有重载
- 运算符 delete[] 有什么作用?
- 编译Qt项目给出了对运算符delete(void*,unsigned int)的未定义引用
- 大小运算符 delete[] 永远不会被调用
- ::运算符 delete(指针) 返回释放的字节大小
- C++:运算符delete(void*)受到保护
- C++中的大小释放:全局运算符delete的正确行为是什么(void*ptr,std::size_t size)
- 将运算符new和运算符delete与自定义内存池/分配器一起使用
- 调用运算符delete时的断言
- 我将如何使用大小运算符delete/delete[],以及它们为什么更好
- 取消运算符delete[]中的析构函数调用