Created
February 22, 2019 09:36
-
-
Save alexandru-dinu/14b427726986f4fa61e96205036667c3 to your computer and use it in GitHub Desktop.
Move
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <string> | |
class Cat { | |
public: | |
std::string s; | |
Cat (const std::string &s) : s(s) {} | |
Cat (const Cat &other) { | |
std::cout << "copy\n"; | |
s = std::move(other.s); // hmm | |
} | |
Cat (Cat &&other) { | |
std::cout << "move\n"; | |
s = std::move(other.s); | |
} | |
void show() { | |
std::cout << "[" + s + "]" << "\n"; | |
} | |
}; | |
int main() { | |
Cat c1("cat1"); | |
Cat c2(std::move(c1)); | |
c1.show(); | |
c2.show(); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment