Item::GetName() function, my code you can see below.
#include <iostream>#include <string>using namespace std;//Generic item classclass Item{public: Item() { name = ""; price = 0; } void SetName(string newName) { name = newName; } void SetPrice(int amount) { price = amount; } string GetName() { return name; } int GetPrice() { return price; }private: std::string name; int price;};//Consumable item derived from generic classclass Potion : public Item{public: Potion() { quantity = 0; } Potion(Potion* newPotion) { CreatePotion(newPotion->GetName(), newPotion->GetPrice()); quantity = 1; } void CreatePotion(string name, int cost) { SetName(name); SetPrice(cost); } void SetQuantity(int amount) { quantity = amount; } void AddQuantity(int amount) { quantity += amount; } int GetQuantity() { return quantity; }private: int quantity;};class Entity{public: void SetName(string newName) { name = newName; } string GetName() { return name; }private: string name;};class Player : public Entity{public: Player() { //do nothing } Player(string name) { SetName(name); } void AddPotion(Potion* potion) { if (potion == NULL) return; //check for duplicate for (int check = 0; check < 15; check++) { if (potionList[check] != NULL) { if (potionList[check]->GetName() == potion->GetName()) { //names are same potionList[check]->AddQuantity(1); return; } } } //no duplicates found for (int loop=0;loop < 15; loop++) { if (potionList[loop] == NULL) { //create a potion here potionList[loop] = new Potion(potion); return; } } cout << "There is no room in your inventory.\n"; cout << endl; } Potion** GetPotionList() { return potionList; } void DisplayPotions() { //list potions cout << "POTIONS\n\n"; Potion** potionlist = GetPotionList(); for (int loop=0;loop < 15;loop++) { if (potionlist[loop] != NULL) { cout << potionlist[loop]->GetQuantity() << " x " << potionlist[loop]->GetName() << endl; } } }private: Potion* potionList[15];};int main(){ bool isRunning = true; Player* Hero = new Player("Heidi"); Potion* PotionList = new Potion[2]; cout << "Name: " << Hero->GetName() << endl; PotionList[0].CreatePotion("HP", 10); PotionList[1].CreatePotion("MP", 5); for(int i = 0; i < 2; i++) { cout << "Name: " << PotionList.GetName() << " - Cost: " << PotionList.GetPrice() << endl; } Hero->AddPotion(&PotionList[0]); Hero->AddPotion(&PotionList[1]); return 0;}