-
Notifications
You must be signed in to change notification settings - Fork 1
Reflect a class
pribault edited this page Jan 28, 2023
·
2 revisions
Class reflection is enabled by the Reflectable class and controled using macros.
To reflect a class you have to:
- include the <CppReflection/Reflectable.h>
- make your class inherit from the CppReflection::Reflectable class
- start reflection using the START_REFLECTION macro
- reflect attributes using the REFLECT_ATTRIBUTE macro
- end reflection using the END_REFLECTION macro
#include <CppReflection/Reflectable.h>
using namespace CppReflection;
class Point : public Reflectable
{
public:
START_REFLECTION(Point)
REFLECT_ATTRIBUTE(x)
REFLECT_ATTRIBUTE(y)
END_REFLECTION()
private:
int x;
int y;
};
class Rectangle : public Point
{
public:
START_REFLECTION(Rectangle, Point)
REFLECT_ATTRIBUTE(w)
REFLECT_ATTRIBUTE(h)
END_REFLECTION()
private:
int w;
int h;
};