How can I add reflection to a C++ application?

前端 未结 28 2368
感动是毒
感动是毒 2020-11-21 11:25

I\'d like to be able to introspect a C++ class for its name, contents (i.e. members and their types) etc. I\'m talking native C++ here, not managed C++, which has reflection

28条回答
  •  南旧
    南旧 (楼主)
    2020-11-21 11:48

    even though reflection is not supported out-of-the-box in c++, it is not too hard to implement. I've encountered this great article: http://replicaisland.blogspot.co.il/2010/11/building-reflective-object-system-in-c.html

    the article explains in great detail how you can implement a pretty simple and rudimentary reflection system. granted its not the most wholesome solution, and there are rough edges left to be sorted out but for my needs it was sufficient.

    the bottom line - reflection can pay off if done correctly, and it is completely feasible in c++.

提交回复
热议问题