⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 new2.c

📁 gcc-you can use this code to learn something about gcc, and inquire further into linux,
💻 C
字号:
// Test that a throw in B's constructor destroys the A and frees the memory.#include <cstddef>#include <cstdlib>#include <new>struct A {  A();  ~A();};struct B {  B (A);};void foo (B*);int newed, created;int main (){  newed = 0; // The libraries might call new before main starts.  try {    foo (new B (A ()));  } catch (...) { }  return !(!newed && !created);}A::A() { created = 1; }A::~A() { created = 0; }B::B(A) { throw 1; }void foo (B*) { }void* operator new (size_t size) throw (std::bad_alloc){  ++newed;  return (void *) std::malloc (size);}void operator delete (void *p) throw (){  --newed;  free (p);}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -