fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. class qwe
  5. {
  6. public:
  7. qwe() {}
  8.  
  9. qwe(char * name, int a, int b):/*_name(strdup(name)),*/ _a(a), _b(b)
  10. {
  11. std::cout << " constructor(char,int,int)" << a << " " << b <<std::endl;
  12. }
  13. qwe& operator = ( const qwe& x )
  14. {
  15. std::cout << " operator = " << std::endl;
  16. this->_a = x._a;
  17. // ...
  18. return *this;
  19. }
  20.  
  21. private:
  22. char * _name;
  23. int _a;
  24. int _b;
  25. };
  26.  
  27. int main()
  28. {
  29. qwe * p = new qwe[10];
  30.  
  31. for (int i = 10; i--;p++)
  32. {
  33. char str[] = "hello";
  34. new(p) qwe( str, 2, 3);
  35. }
  36. }
  37.  
Success #stdin #stdout 0s 16064KB
stdin
Standard input is empty
stdout
 constructor(char,int,int)2 3
 constructor(char,int,int)2 3
 constructor(char,int,int)2 3
 constructor(char,int,int)2 3
 constructor(char,int,int)2 3
 constructor(char,int,int)2 3
 constructor(char,int,int)2 3
 constructor(char,int,int)2 3
 constructor(char,int,int)2 3
 constructor(char,int,int)2 3