jeudi 27 septembre 2018

Declaring Arbitrary Number of Data Members with Variadic Templates

I have a class name that is defined under different specifications, and the class attributes and their corresponding data types change between the specifications. For example, the same class may have new attributes added to it or subtracted from it. In addition, types of these data members also change.

Now, what I want to do is to design a variadic template, so that I can pass these modified class data members from different specifications to one skeleton template class. For example,

template <typename ... T>
class X { .... };
// Now intended use:

X <Type1, Type2, Type3> first_spec (value1, value2, value3);
X <Type5, Type6, Type7, Type8, Type9> second_spec(value5, value6, value7, value8, value9);

The specs share the same member functions but number of data members and their corresponding data types change between specifications.

Aucun commentaire:

Enregistrer un commentaire