At a loss here hope someone can help..
I have the following class structure.
A base class Room with two child classes Kitchen, and livingRoom.
I have a vector in my base class
up = nullptr;
down = nullptr;
left = nullptr;
right = nullptr;
pocket = new vector<string>;
void Room::addPocket(string item)
emptyPocket = 'N';
cout << "Item added to pocket" << endl;
cout <<"Your pocket is full" << endl;
cout <<"Would you like to empty your pocket? 'Y' or 'N'" << endl;
cin >> emptyPocket;
if(emptyPocket == 'Y' || emptyPocket == 'y')
cout <<"You have emptied your pocket." << endl;
Base class data is not shared between different instances of child classes. Each child class is, and effectively contains, a distinct instance of the base class.
Kitchen has a
livingRoom has another
Instead, you should look into making another class to represent the entity that is moving between the rooms and have this entity class contain
Also shy away from dynamically allocating
std::vectors. They were designed to take away all of the responsibilities of managing dynamic allocations, so dynamically allocating a
vector merely puts some of the those management responsibilities back into play for no benefit.