#include #include #include #include using namespace std; struct Effect { string name{}; }; class Spell { public: Spell(string const& spell_name, initializer_list il) :name{spell_name}, effects{} { for(auto e : il) { effects.push(new Effect{e}); } } //STARTSOLUTION Spell(Spell const& other) = delete; // Spell& operator=(Spell const& other) = delete; // Spell(Spell && other) // : name{}, effects{} { swap(name, other.name); swap(effects, other.effects); } Spell& operator=(Spell && other) // { swap(name, other.name); swap(effects, other.effects); return *this; } ~Spell() // { while( !effects.empty() ) { delete effects.top(); effects.pop(); } } void cast(ostream& os) { os << "Casting " << name << ": "; while( !effects.empty() ) { os << effects.top() -> name; delete effects.top(); effects.pop(); if( !effects.empty() ) { os << " -> "; } } os << endl; } //ENDSOLUTION private: string name; stack effects; }; //Denna funktion kontrollerar att det inte går att kopiera Spell void check_copy_ability() { if(is_copy_assignable::value) { cout << "Wrong, the spell can be copied using the assignment operator(=)" << endl; } else { cout << "Correct, the spell can not be copied using the assignment operator(=)" << endl; } if(is_copy_assignable::value) { cout << "Wrong, the spell can be copied using the copy constructor" << endl; } else { cout << "Correct, the spell can not be copied using the copy constructor" << endl; } cout << endl; } int main() { check_copy_ability(); Spell spell1{"Voldos awesome incantation", {"Levitate", "Teleport"}}; Spell spell2{"Ulagasts incineration", {"Burning Hands", "Fireball", "Firebolt", "Evil laughter"}}; Spell movedSpell1{move(spell1)}; Spell movedSpell2 = move(spell2); Spell movedSpell3{"Voldos kinda cool incantation", {"Float", "Blink"}}; movedSpell3 = move(movedSpell2); movedSpell1.cast(cout); }