简体   繁体   中英

C++: get superclasses type index from type index

I have a template type T , that subclasses Base (must not be directly). By using

std::type_index(typeid(T)) ,

I can get a metadata object for T . Is there a way to get a std::type_index for every superclass of T , so that I can traverse the superclasses upwards until Base is reached?

I know C++ doesn't provide reflection by itself, but maybe someone knows some template magic.

In detail: I want to put pointers of objects into a map, indexed by the objects type. It would be nice to be able to insert the objects not just as their own type, but as their supertypes, too.

似乎您正在寻找类似std :: bases之类的东西,它在c ++标准中不支持,但在gcc中实现(您可以在此处阅读更多内容)。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM