From cc3460cee743a3607101fdc8d58bf0f89e3537e1 Mon Sep 17 00:00:00 2001 From: liuzicheng1987 Date: Mon, 8 Jan 2024 08:28:14 +0800 Subject: [PATCH] Update structs.md because you now can declare them inside functions --- docs/structs.md | 35 +---------------------------------- 1 file changed, 1 insertion(+), 34 deletions(-) diff --git a/docs/structs.md b/docs/structs.md index dc2997ae..ec984863 100644 --- a/docs/structs.md +++ b/docs/structs.md @@ -69,7 +69,7 @@ And you can parse it back into a struct: const auto homer = rfl::json::read(json_string).value(); ``` -## Important notes +## Important note **Do not create custom constructors on the structs.** @@ -84,36 +84,3 @@ But if you create a custom constructor, then C++ will no longer allow this kind 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). -**Do not define the struct inside a function.** - -Another limitation is that you cannot declare the struct inside a function. For instance: - -```cpp -// WILL NOT COMPILE -void my_function() { - - struct Person { - std::string first_name; - std::string last_name; - std::vector children; - }; - - // ... -} -``` - -Instead, do this: - -```cpp -struct Person { - std::string first_name; - std::string last_name; - std::vector children; -}; - -void my_function() { - - // ... -} -``` -