Can one object have multiple classes?

Viewed 51

Want to make a simple multiplayer console game. My "World" class consists of a 2d vector of objects of a class "Block". I want for "Block" to have some kind of attribute that can have different types. Is this something I could do?

class Block {
public:
    string name = "";
    string type = "";
    int color = 7;
    bool transparent = true;
    char symbol = ' ';
    string tool = "";
    Item drop;
    bool interactable = false;
    string getName(){return name;};
    string getType(){return type;};
    char getSymbol(){return symbol;};
    Item getDrop(){return drop;};
    int getColor(){return color;};
    bool isTransparent(){return transparent;};
    string getTool(){return tool;}
    bool isInteractable(){return interactable;};
    void setName(string name){this->name = name;};
    void setType(string type){this->type = type;};
    void setSymbol(char symbol){this->symbol = symbol;};
    void setDrop(Item drop){this->drop = drop;};
    void setTransparent(bool transparent){this->transparent = transparent;};
    void setTool(string tool){this->tool = tool;};
    void setColor(int color){this->color = color;};
    void setInteractable(bool b){this->interactable = b;};
};
0 Answers
Related