Skip to content

Instantly share code, notes, and snippets.

@thiagomg
Last active August 29, 2015 14:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thiagomg/210a4a3dd8a3eed539e8 to your computer and use it in GitHub Desktop.
Save thiagomg/210a4a3dd8a3eed539e8 to your computer and use it in GitHub Desktop.
//Construtor padrão
TestCopy() {
cout << "[CONSTR 1]" << endl;
this->val = 0;
}
//Construtor parametrizado
TestCopy(T val) {
cout << "[CONSTR 2:" << val << "]" << endl;
this->val = val;
}
//Copy constructor
TestCopy(const TestCopy &src) {
cout << "[COPY]" << endl;
this->val = src.val;
}
//Move constructor – Note que não há const e tem dois “&” na assinatura
TestCopy(TestCopy &&src) {
cout << "[MOVE]" << endl;
this->val = std::move(src.val);
}
//Operador = (atribuição)
TestCopy &operator =(const TestCopy &src) {
cout << "[OP=" << src.val << "]" << endl;
this->val = src.val;
}
//Final do programa + função auxiliar
void ts() {
cout << val << "===============" << endl;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment