Class inheritance and generalization... or something.

[b][red]This message was edited by MarauderIIC at 2003-6-29 19:33:36[/red][/b][hr]
I have something like this:

[code]
class Item {
string usename;
unsigned int index;
unsigned int eqloc;
};

class Weapon : public Item {
unsigned int hitdie;
unsigned int dmgdie;
};

class Armor : public Item {
bool shield;
unsigned int ac;
}
[/code]
(edit: whoops, forgot to close code tag)

How can I do, something like vectorinventory; and still list weapons and items, etc? Or, vectorequipped and be able to add weapons and armor to it? I figure I'm going about it the wrong way, so any help is appreciated :)

Comments

  • : [b][red]This message was edited by MarauderIIC at 2003-6-29 19:33:36[/red][/b][hr]
    : I have something like this:
    :
    : [code]
    : class Item {
    : string usename;
    : unsigned int index;
    : unsigned int eqloc;
    : };
    :
    : class Weapon : public Item {
    : unsigned int hitdie;
    : unsigned int dmgdie;
    : };
    :
    : class Armor : public Item {
    : bool shield;
    : unsigned int ac;
    : }
    : [/code]
    : (edit: whoops, forgot to close code tag)
    :
    : How can I do, something like vectorinventory; and still list weapons and items, etc? Or, vectorequipped and be able to add weapons and armor to it? I figure I'm going about it the wrong way, so any help is appreciated :)
    :
    :
    [code]
    vectorinventory;

    inventory.push_back (new Weapon);
    inventory.push_back (new Armor);
    [/code]
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

In this Discussion