Reflection in C++

后端 未结 8 1855
失恋的感觉
失恋的感觉 2021-02-05 19:55

I\'ve been working for years with Java. During those years, I\'ve made extensive (or maybe just frequent) use of reflection, and found it useful and enjoyable. But 8 months ago

8条回答
  •  庸人自扰
    2021-02-05 20:12

    Since C++ standard does not cover such concept as "metadata", there's no portable (across different compilers and platforms, for that matter) method of run-time reflection other than RTTI you already mentioned.

    In C++, there's also a possibility of compile-time reflection (think boost::type_traits and boost::type_of), but it's limited as well compared to, say, Nemerle or LISP.

    Most major frameworks (MFC, Qt, etc.) allow you to extract metainformation at run-time, but they require all kinds of special annotations for it to work (see RUNTIME_CLASS et al as an example).

提交回复
热议问题