functions in inherited classes

hello everybody
i'm trying to create a little text game (actually just parts of it).

now i'm stuck on how to communicate derived classes. considering this code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
class Item{

};

class Entity{
public:
    std::string name;
    int hp;
};

class ItemHolder{
    std::vector<Item*> items;
    size_t max_items;
};

class MoneyHolder{
    int money;
};

class NPC : public Entity, public ItemHolder, public MoneyHolder{
	
};

class Player : public Entity, public ItemHolder, public MoneyHolder{

};



i'd like to make negotiations between Player and NPCs. i have this up to now:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
void trade(Entity& trader, int c_money, int g_money, Item& c_item, Item& g_item){ //coming/going money and items
	if (trader.money >= c_money && money >= g_money){
	money += c_money - g_money;
        items.append(c_item);
        items.remove(g_item);
        trader.money += g_money - c_money;
        trader.items.append(g_item);
        trader.items.remove(c_item);
	}

        else {
            /*negotiation can't be done*/
        }
    }


but i can't find where to put this function and how to make it work.
and before anyone asks, i need the classes to be like this (instead of a big class that holds everything) for learning purposes and because there will be other Entities that will not hold money or items.

thanks in advance! :)
Stauricus wrote:
but i can't find where to put this function and how to make it work.
What do you mean? You could place this function in global scope (or a user defined namespace). What's the problem?
Last edited on
Topic archived. No new replies allowed.