fork download
  1. #include <iostream>
  2. #include <bits/stdc++.h>
  3. using namespace std;
  4.  
  5. class X {
  6. public:
  7.  
  8. int a{0};
  9.  
  10. X() {
  11. std::cout << "X constructor \n";
  12. }
  13.  
  14. ~X() {
  15. std::cout << "X destructor \n";
  16. }
  17.  
  18. X(const X& t)
  19. {
  20. a = t.a;
  21. cout << "Copy constructor called " << endl;
  22. }
  23.  
  24. X& operator=(const X& t)
  25. {
  26. a = t.a;
  27. cout << "Copy assignment operator called " << endl;
  28. return *this;
  29. }
  30.  
  31. X(const X&& t)
  32. {
  33. a = std::move(t.a);
  34. cout << "Move constructor called " << endl;
  35. }
  36.  
  37. X& operator=(const X&& t)
  38. {
  39. a = std::move(t.a);
  40. cout << "Move assignment operator called " << endl;
  41. return *this;
  42. }
  43. };
  44.  
  45. std::function<void(int)> ff;
  46.  
  47. int main() {
  48. {
  49. auto x = std::make_shared<X>();
  50. // const auto x = new X();
  51. ff = [x](int t) {
  52. std::cout << x->a << " " << t << "\n";
  53. };
  54. }
  55.  
  56. ff(1);
  57. ff(2);
  58. ff(3);
  59. return 0;
  60. }
Success #stdin #stdout 0s 5516KB
stdin
Standard input is empty
stdout
X constructor 
0 1
0 2
0 3
X destructor