fork download
  1. #include <iostream>
  2. #include <stdlib.h>
  3.  
  4. struct B{
  5. B(){std::cout<<"B("<<(void*)this<<")"<<std::endl;}
  6. ~B(){std::cout<<"B("<<(void*)this<<") del"<<std::endl;}
  7. };
  8. struct A : B{
  9. A(){std::cout<<"A("<<(void*)this<<")"<<std::endl;}
  10. ~A(){std::cout<<"A("<<(void*)this<<") del"<<std::endl;}
  11. };
  12.  
  13. int main(){
  14. A* p = (A*)malloc(sizeof(A));
  15. std::cout<<(void*)p<<std::endl;
  16. new(p) A();
  17. p->~A();
  18. free(p);
  19. return 0;
  20. }
Success #stdin #stdout 0.02s 2860KB
stdin
Standard input is empty
stdout
0x88d3008
B(0x88d3008)
A(0x88d3008)
A(0x88d3008) del
B(0x88d3008) del