Created
February 8, 2021 07:26
-
-
Save cfrank/01bcbb63e95563cbee02c3e09049b811 to your computer and use it in GitHub Desktop.
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> | |
class CopyMe { | |
public: | |
CopyMe(std::string name) | |
: m_name(name) | |
{} | |
CopyMe(const CopyMe& other) | |
{ | |
std::cout << "Copying CopyMe\n"; | |
m_name = other.m_name; | |
} | |
CopyMe(CopyMe&& other) noexcept | |
{ | |
std::cout << "Moving CopyMe\n"; | |
m_name = other.m_name; | |
} | |
~CopyMe() | |
{ | |
std::cout << "Destroying CopyMe!\n"; | |
} | |
void Print() const | |
{ | |
std::cout << m_name << '\n'; | |
} | |
private: | |
std::string m_name; | |
}; | |
class Testing { | |
public: | |
Testing() | |
: m_copy(CopyMe("Default Name")) | |
{} | |
Testing(const CopyMe& copy) | |
: m_copy(copy) | |
{} | |
Testing(CopyMe&& copy) | |
: m_copy(std::move(copy)) | |
{} | |
void Test() const | |
{ | |
m_copy.Print(); | |
} | |
private: | |
CopyMe m_copy; | |
}; | |
int main() { | |
// Testing test; | |
Testing test(CopyMe("John Doe")); | |
test.Test(); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment