fork download
  1. #include <stdlib.h>
  2. #include <iostream>
  3.  
  4. struct a
  5. {
  6. virtual ~a(){};
  7. void* operator new[] (size_t s)
  8. {
  9. void* p = malloc(s);
  10. std::cout << "malloc returned " << p << std::endl;
  11. return p;
  12. }
  13.  
  14. void operator delete[] (void* p)
  15. {
  16. std::cout << "delete[] got " << p << std::endl;
  17. free(p);
  18. }
  19. };
  20.  
  21. struct b
  22. {
  23. int x;
  24. };
  25.  
  26. struct c: b, a
  27. {
  28. int y;
  29. };
  30.  
  31. int main ()
  32. {
  33. c* cc = new c[10];
  34. std::cout << "new[] expression returned " << (void*)cc << std::endl;
  35. delete[] cc;
  36. }
Success #stdin #stdout 0.01s 2856KB
stdin
Standard input is empty
stdout
malloc returned 0x96be008
new[] expression returned 0x96be00c
delete[] got 0x96be008