Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- struct X
- {
- X(const char *) { std::cout << 1; }
- X(const X&) {std::cout << 2;} //copy ctor;
- X(X&& ) {std::cout << 3;} //Move ctor;
- };
- X f(X a)
- {
- return a; //a will be moved out of f calling X's move ctor
- }
- X g(const char* b)
- {
- X c(b);
- return c;
- }
- int main()
- {
- f("hello");
- g("hello");
- //prints 131 and not 1313
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement