C++ struct with template in vector

Viewed 293

I'm making a text adventure game in C++. This is the struct for an object in that game (something the user can pick up and put in the inventory)

template <int N>
struct Object
{
    static const int length = N;
    string names[N];
    string description;
};

Examples of objects:

Object<2> flower = { {"flower", "the flower"}, "A strange looking flower"};
Object<3> book = { { "the book", "book", "recipe book" }, "The world's finest cocktail recipes now all in one easy to use companion." };

The multiple names are synonyms for the command parser, so the user can input "pick up book" or "pick up recipe book", which in both cases picks up the object book.

Now I'd like to create a vector inventory to store all the elements in the inventory.

vector<Object> inventory;

Now, off course, this gives me a compiler error, because it expects something like this:

vector<Object<5>> inventory;

However, some objects have more names than others, is something like this possible and if so, how?

vector<Object<N>> inventory;
3 Answers
Related