Advertisement
Guest User

Untitled

a guest
Apr 19th, 2014
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.37 KB | None | 0 0
  1. #include <iostream>
  2. struct X
  3. {
  4. X(const char *) { std::cout << 1; }
  5. X(const X&) {std::cout << 2;} //copy ctor;
  6. X(X&& ) {std::cout << 3;} //Move ctor;
  7. };
  8.  
  9. X f(X a)
  10. {
  11. return a; //a will be moved out of f calling X's move ctor
  12. }
  13.  
  14. X g(const char* b)
  15. {
  16. X c(b);
  17. return c;
  18. }
  19. int main()
  20. {
  21. f("hello");
  22. g("hello");
  23.  
  24. //prints 131 and not 1313
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement