How can I check the types of derived classes? (C++ Instanceof)

后端 未结 2 596
甜味超标
甜味超标 2021-01-23 17:38

Let\'s say I have some base abstract class and three different classes that derive and implement its methods. Is there is a \'Type\' object like as in C#? Or in other words, how

2条回答
  •  囚心锁ツ
    2021-01-23 18:26

    In addition to other answers, you might generate some C++ code doing what you want. Consider for example using GPP from your build automation tool (e.g. Makefile) or write a simple AWK, Guile, or Python script doing what you want (or some ad-hoc C++ generator above ANTLR, inspired by SWIG), and generating some C++ code per your needs. My obsolete GCC MELT did that (dynamically, at runtime) on Linux.

    Qt has a meta-object protocol doing exactly this. You might get inspiration from its moc (which is open source) generating C++ code.

    Look also into the ongoing (but -in February 2020- embryonic) RefPerSys project. We want to use these ideas, and we are starting to implement them. Observe that on Linux dlopen could be called thousands of times in practice, on shared objects produced by compilation of generated and temporary C++ code.

提交回复
热议问题