Hey i have a function that contains the STL container vector.
void displayInventory()
{
vector<string> inventory;
cout<< "You have " << inventory.size() << " items.\n";
cout<< "\nYouritems:\n";
for (int i= 0; i< inventory.size(); ++i)
cout<< inventory[i] << endl;
}
And i wanna use the actual vector in another method play game.
int playGame()
{
inventory.push_back("sword"); //This is an error. Expression must have class.
}
Can anyone help me do this without having to globalize the vector declaration ?
You can receive it as a function parameter: