fork(1) download
  1. #include <iostream>
  2.  
  3. using namespace std;
  4. class A
  5. {
  6. public:
  7. int x;
  8. A(){}
  9. };
  10.  
  11. class B
  12. {
  13. public:
  14. int x;
  15. B()=default;
  16. };
  17.  
  18.  
  19. int main()
  20. {
  21. int x = 5;
  22. new(&x)A(); // Call for empty constructor, which does nothing
  23. cout << x << endl;
  24. x = 5;
  25. new(&x)B; // Call for default constructor
  26. cout << x << endl;
  27. x = 5;
  28. new(&x)B(); // Call for default constructor + Value initialization
  29. cout << x << endl;
  30. return 0;
  31. }
Success #stdin #stdout 0.01s 5440KB
stdin
Standard input is empty
stdout
0
5
0