Created
June 6, 2015 22:01
-
-
Save rootid/929e4b14fa71199c944c to your computer and use it in GitHub Desktop.
Generic copy ctor in c++
This file contains hidden or 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
//Copy-Constructor and assignment operator | |
MyClass::MyClass() : /* Fill in initializer list. */ { | |
/* Default initialization here. */ | |
} | |
//copy constructor | |
MyClass::MyClass(const MyClass& other) { | |
copyOther(other); | |
} | |
//assignmet-operator | |
MyClass& MyClass::operator =(const MyClass& other) { | |
if(this != &other) { | |
clear(); | |
// Note: When we cover inheritance, there's one more step here. | |
copyOther(other); | |
} | |
return *this; | |
} | |
MyClass::~MyClass() { | |
clear(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment