how do you call a member function from a member function? What am i missing? it could just be that it is 6AM lol
im trying to call medkit.stat() from store::storeMenu()
when i compile i get medkit out of scope in the member function
class
1 2 3 4 5 6 7 8 9 10
class store
{
public:
string name;
string desc; //decription
int price;
void stat(); // display item information
void storeMenu(); //display menu of items and options
store();
};
int main()
{
store medkit;
medkit.name = "Medical Kit";
medkit.price = 100;
medkit.desc = "A medkit will heal your party's wounds. ";
......}
in addition to my original question, i was wondering about all the data members and member functions of the class store? they fill a bit of main, Is there any way to get some of that code out of main???
If medkit has been declared in main(), storeMenu() has no knowledge of it. You should either make madkit a member of store or pass it to storeMenu(). Note that logically medkit is not a store, it's an item. You need to write an item class and give store a list (array or vector) of those.
I see a lot of other problems with this. To access it using the identifier would require it to be a static member. However, this is terrible practice. You might want to store it (like the above) in a list, map or a vector array. Then you could loop through and allow it to be accessed using a const/enum or string.