Skip to content

Instantly share code, notes, and snippets.

@alexandru-dinu
Created February 22, 2019 09:36
Show Gist options
  • Save alexandru-dinu/14b427726986f4fa61e96205036667c3 to your computer and use it in GitHub Desktop.
Save alexandru-dinu/14b427726986f4fa61e96205036667c3 to your computer and use it in GitHub Desktop.
Move
#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