Skip to content

Instantly share code, notes, and snippets.

@cfrank
Created February 8, 2021 07:26
Show Gist options
  • Save cfrank/01bcbb63e95563cbee02c3e09049b811 to your computer and use it in GitHub Desktop.
Save cfrank/01bcbb63e95563cbee02c3e09049b811 to your computer and use it in GitHub Desktop.
#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