Unfortunately, current virtual tables cannot (portable) directly contain "virtual data", that is, metadata common to the class level.
You can make a virtual method by pointing to some X ...
You can also use typeinfo , i.e. typeid (in C ++ 11). For example, you can define a static hash table
static std::unordered_map<std::typeinfo,X*> map; X* getX() { return map[typeid(this)]; };
Then you need to fill in the map correctly.
Basile starynkevitch
source share