fork download
  1. #include <iostream>
  2.  
  3. struct CButton
  4. {
  5. int x, y, z;
  6. CButton() : x(0), y(0), z(0)
  7. {
  8. std::cout << "Default Constructor" << std::endl;
  9. }
  10. CButton(const CButton &from) : x(from.x), y(from.y), z(from.z)
  11. {
  12. std::cout << "Copy Constructor" << std::endl;
  13. }
  14. CButton(int x, int y, int z) : x(x), y(y), z(z)
  15. {
  16. std::cout << "x, y, z Constructor" << std::endl;
  17. }
  18. ~CButton()
  19. {
  20. std::cout << "Destructor" << std::endl;
  21. }
  22. };
  23.  
  24. int main()
  25. {
  26. CButton *pBtn = (CButton*)operator new(sizeof(CButton)*4);
  27. for(unsigned i = 0; i < 4; ++i)
  28. {
  29. new (pBtn+i) CButton(3, 4, 5);
  30. }
  31. delete pBtn;
  32. }
Success #stdin #stdout 0.01s 2856KB
stdin
Standard input is empty
stdout
x, y, z Constructor
x, y, z Constructor
x, y, z Constructor
x, y, z Constructor
Destructor