fork(1) download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int i = 0;
  5.  
  6. struct A
  7. {
  8. A() { cout << "A()\n"; if(i++ > 0) throw 42; }
  9. ~A() { cout << "~A()\n"; }
  10. void * operator new [] (size_t t, int, int)
  11. {
  12. cout << "3 parameters allocation" << endl;
  13. return ::operator new[](t);
  14. }
  15.  
  16. void operator delete [] (void *p, int, int)
  17. {
  18. cout << "3 parameters deallocation" << endl;
  19. return ::operator delete[](p);
  20. }
  21. };
  22.  
  23. int main()
  24. {
  25. try{
  26. A *a = new (5,5) A[10]; //operator new [] (size_t, int, int) invoked
  27. }catch(...) {}
  28. //delete [] a; //Error. Overload resolution is failed.
  29. }
Success #stdin #stdout 0s 3428KB
stdin
Standard input is empty
stdout
3 parameters allocation
A()
A()
~A()
3 parameters deallocation