-
Notifications
You must be signed in to change notification settings - Fork 110
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Derived Struct (Nested Struct) #239
Comments
I suppose you could try to write a custom parser (refer to the documentation). But I think the bigger question is: Why do you want to do this? |
I don't want to implement the custom parser for the derived struct just because I'm lazy:) |
OK, fair enough, but the question is what are you trying to do in the first place? Personally, I can't think of any good reason to inherit from rfl::Field... |
|
I am a junior at |
Especially the logic in the internal namespace. |
A Tip: option(REFLECT_CPP_C_ARRAYS_OR_INHERITANCE "Enable C arrays and inheritance" ON) |
rfl::Field
?
Hi @DapengFeng, inheritance is a bit of a tricky topic. We use structured bindings to automatically access the fields and so far no one has thought of a way to do this with inheritance. You might also want to take a look at rfl::Flatten. Maybe that would solve your problem. |
Thank you for your advice. I try to learn |
Can I use the operator[] to access the named field in the runtime? |
@DapengFeng , sure: https://github.com/getml/reflect-cpp/blob/main/docs/generic.md You could try something like: const auto obj = rfl::to_generic(my_struct).to_object().value();
obj["my_field"]; |
If I define a struct derived from the base struct
rfl::Field,
how can I implement the parser for the new struct?The text was updated successfully, but these errors were encountered: