ABSTRACT

So, what can we do in C++? Using only the standard language and library, we can’t do much. You can find out the name of a type (using typeid), and the size of a type (using sizeof), and that’s about it. You can also find out whether a given object instance derives from a given base class (using the horribly expensive dynamic_cast<>), but only if the type has a virtual table, and you can’t iterate over the set of base classes that it derives from, except perhaps by testing against all possible base classes. Despite these draw-backs, C++ game programmers still need to deal with data, display it in editors, save it to files, send it over networks, wire compatible properties together in object/component systems, and do all the other data-driven game development magic that a modern game engine must provide. Trying to solve this problem, many engines end up with a number of different mechanisms to describe the data in a given object, entity, or data structure. For example, you may end up having to write code that’s something like what is shown in Listing 25.2.