...

/

Discussion: Monsters on the Move

Discussion: Monsters on the Move

Execute the code to understand the output and gain insights into constructor behavior and value categories.

Run the code

Now, it’s time to execute the code and observe the output.

Press + to interact
#include <iostream>
struct Monster
{
Monster() = default;
Monster(const Monster &other)
{
std::cout << "Monster copied\n";
}
Monster(Monster &&other)
{
std::cout << "Monster moved\n";
}
};
struct Jormungandr : public Monster
{
Jormungandr() = default;
Jormungandr(const Jormungandr &other) : Monster(other)
{
std::cout << "Jormungandr copied\n";
}
Jormungandr(Jormungandr &&other) : Monster(other)
{
std::cout << "Jormungandr moved\n";
}
};
int main()
{
Jormungandr jormungandr1;
Jormungandr jormungandr2{std::move(jormungandr1)};
}

Understanding the output

When we ...