#include #include #include using namespace std; class EnemyLookup { public: EnemyLookup(): lookup{} {} void add_enemy(string const& key, string const& name, int hp) { if (lookup.find(key) != lookup.end()) { // If key already exists delete previous enemy // then write new enemy pointer to that key delete(lookup[key]); lookup[key] = new Enemy{name, hp}; } else { lookup[key] = new Enemy{name, hp}; } } void remove_enemy(string const& key) { delete lookup[key]; lookup.erase(key); } void print() const { cout << "EnemyLookup:\n====\n"; for( auto && enemy: lookup ) { cout << enemy.second->name << ": " << enemy.second->hp << endl; } } private: struct Enemy { string name; int hp; }; map lookup; }; //Denna funktion kontrollerar att det inte går att kopiera Spell void check_copy_ability() { cout << "\n"; if(is_copy_assignable::value) { cout << "Wrong, the enemyLookup can be copied using the assignment operator(=)" << endl; } else { cout << "Correct, the enemyLookup can not be copied using the assignment operator(=)" << endl; } if(is_copy_assignable::value) { cout << "Wrong, the enemyLookup can be copied using the copy constructor" << endl; } else { cout << "Correct, the enemyLookup can not be copied using the copy constructor" << endl; } cout << endl; } int main() { EnemyLookup eq{}; eq.add_enemy("Redbanner", "Marauder", 10); eq.add_enemy("Bluebanner", "Warg", 15); eq.add_enemy("Greybanner", "Goblin", 5); eq.print(); EnemyLookup meq{std::move(eq)}; check_copy_ability(); return 0; }