fork(6) download
  1. #include <iostream>
  2. #include <vector>
  3. using namespace std;
  4.  
  5. struct TS{
  6. TS(){
  7. cout<<"default constructor\n";
  8. }
  9.  
  10. TS(const TS &other) {
  11. cout<<"Copy constructor\n";
  12. }
  13.  
  14. TS(TS &&other) noexcept{
  15. cout<<"Move constructor\n";
  16. }
  17.  
  18. TS& operator=(TS const& other)
  19. {
  20. cout<<"Copy assigment\n";
  21. return *this;
  22. }
  23.  
  24. TS& operator=(TS const&& other) noexcept
  25. {
  26. cout<<"Move assigment\n";
  27. return *this;
  28. }
  29.  
  30. ~TS(){
  31. cout<<"destructor\n";
  32. }
  33.  
  34. };
  35.  
  36. int main() {
  37. TS ts1;
  38. TS ts2;
  39. cout<<"-----------------------------------------\n";
  40. std::vector<TS> vec {ts1, ts2};
  41. //vec.push_back(ts1);
  42. //vec = {ts1, ts2};
  43. cout<<"-----------------------------------------\n";
  44.  
  45.  
  46.  
  47. return 0;
  48. }
Success #stdin #stdout 0s 3428KB
stdin
Standard input is empty
stdout
default constructor
default constructor
-----------------------------------------
Copy constructor
Copy constructor
Copy constructor
Copy constructor
destructor
destructor
-----------------------------------------
destructor
destructor
destructor
destructor