I think this can be a better answer to your question since you need to understand all of the special member functions and not just the copy constructor.
Now take a look at this:
#include <iostream>
#include <utility>
#include <string>
class Kat
{
public:
Kat( )
:msg( "Default Msg" )
{
std::clog << "default ctor" << '\n';
}
Kat( const std::string& message )
: msg( message )
{
std::clog << "parameterized ctor" << '\n';
}
Kat( const Kat& rhs ) // copy ctor
: msg( rhs.msg )
{
std::clog << "copy ctor" << '\n';
}
Kat& operator=( const Kat& rhs ) // copy assignment operator
{
if ( this != &rhs )
{
msg = rhs.msg;
}
std::clog << "copy assignment operator" << '\n';
return *this;
}
Kat( Kat&& rhs ) noexcept // move ctor
: msg( rhs.msg )
{
rhs.msg = "";
std::clog << "move ctor" << '\n';
}
Kat& operator=( Kat&& rhs ) noexcept // move assignment operator
{
if ( this != &rhs )
{
msg = rhs.msg;
rhs.msg = "";
}
std::clog << "move assignment operator" << '\n';
return *this;
}
private:
std::string msg;
};
int main( )
{
Kat kat1; // default ctor
Kat kat2( "hello kitty" ); // parameterized ctor
Kat kat3 = kat2; // copy ctor
Kat kat4( kat2 ); // also copy ctor
kat1 = kat2; // copy assignment operator
Kat kat5 = std::move( kat2 ); // move ctor
Kat kat6( std::move( kat3 ) ); // also move ctor
kat6 = std::move( kat1 ); // move assignment operator
return 0;
}
And the output:
default ctor
parameterized ctor
copy ctor
copy ctor
copy assignment operator
move ctor
move ctor
move assignment operator