From 96987b09ef780a4af0efba6bf1ba4f4c7dd5801d Mon Sep 17 00:00:00 2001 From: liuzicheng1987 Date: Wed, 4 Oct 2023 20:22:01 +0200 Subject: [PATCH] Added note on custom constructors --- docs/structs.md | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/docs/structs.md b/docs/structs.md index cc4ab153..09e17399 100644 --- a/docs/structs.md +++ b/docs/structs.md @@ -70,3 +70,18 @@ And you can parse it back into a struct: ```cpp const auto homer = rfl::json::read(json_string).value(); ``` + +## Important note + +**Do not create custom constructors on the structs.** + +reflect-cpp needs to be able to create the structs like this: + +```cpp +Person{rfl::Field<"firstName", std::string>("Bart"), rfl::Field<"lastName", std::string>("Simpson"), ...}; +``` + +But if you create a custom constructor, then C++ will no longer allow this kind of constructions. + +If you want to create the struct from one of your classes (the most like reason, you want to create custom constructors in the first place), +you might want to check out the section on [custom classes](https://github.com/getml/reflect-cpp/blob/main/docs/custom_classes.md) or [custom parsers](https://github.com/getml/reflect-cpp/blob/main/docs/custom_parser.md).