Skip to content

Commit cc3460c

Browse files
Update structs.md because you now can declare them inside functions
1 parent 05b6955 commit cc3460c

File tree

1 file changed

+1
-34
lines changed

1 file changed

+1
-34
lines changed

docs/structs.md

+1-34
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ And you can parse it back into a struct:
6969
const auto homer = rfl::json::read<Person>(json_string).value();
7070
```
7171

72-
## Important notes
72+
## Important note
7373

7474
**Do not create custom constructors on the structs.**
7575

@@ -84,36 +84,3 @@ But if you create a custom constructor, then C++ will no longer allow this kind
8484
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),
8585
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).
8686
87-
**Do not define the struct inside a function.**
88-
89-
Another limitation is that you cannot declare the struct inside a function. For instance:
90-
91-
```cpp
92-
// WILL NOT COMPILE
93-
void my_function() {
94-
95-
struct Person {
96-
std::string first_name;
97-
std::string last_name;
98-
std::vector<Person> children;
99-
};
100-
101-
// ...
102-
}
103-
```
104-
105-
Instead, do this:
106-
107-
```cpp
108-
struct Person {
109-
std::string first_name;
110-
std::string last_name;
111-
std::vector<Person> children;
112-
};
113-
114-
void my_function() {
115-
116-
// ...
117-
}
118-
```
119-

0 commit comments

Comments
 (0)