cc++ new delete 思考

xiaoxiao2026-05-28  1

/* #include <iostream> using namespace std; */ #include <stdio.h> #include <stdlib.h> #include <new> void* operator new(size_t size) { printf("malloc %u\n", size); return malloc(size); } void operator delete(void *memblock) { printf("free\n"); free(memblock); } class abc { public: abc() { printf("abc\n"); throw int(); } ~abc(){printf("~abc\n");} }; int main() { abc* p = NULL; try { p = new abc; } catch(int& i) { printf("%d\n", i); } delete(p); return 0; }

转载请注明原文地址: https://www.6miu.com/read-5049552.html

最新回复(0)