Skip to content

Commit

Permalink
Update structs.md because you now can declare them inside functions
Browse files Browse the repository at this point in the history
  • Loading branch information
liuzicheng1987 authored Jan 8, 2024
1 parent 05b6955 commit cc3460c
Showing 1 changed file with 1 addition and 34 deletions.
35 changes: 1 addition & 34 deletions docs/structs.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ And you can parse it back into a struct:
const auto homer = rfl::json::read<Person>(json_string).value();
```

## Important notes
## Important note

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

Expand All @@ -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<Person> children;
};
// ...
}
```

Instead, do this:

```cpp
struct Person {
std::string first_name;
std::string last_name;
std::vector<Person> children;
};

void my_function() {

// ...
}
```

0 comments on commit cc3460c

Please sign in to comment.