As far as I know, C++ does not support reflection or introspection out-of-the-box. There have been various suggestions for hacks to achieve similar functionality, but I don't know that any of these has wide acceptance. In general, they all seem to revolve around defining some macros that let you manually "register" your class/message structure at compile-time, for later introspection at run-time.
Here's a similar ROS request from a few years ago with a similar (negative) response. In that case, there was also a suggestion to do the introspection on the .msg definition file, and use that info to extract data from the serialized message stream. This would work, but might end up being more trouble than it's worth.
There was even an enhancement request filed 4 years ago for this very feature. But it was closed as "wontFix" at the time. The suggestion was to just use python instead.
For your application, I'd say it feels like the hardcoded switch-style that dornhege suggested would be the easiest method (assuming you have a limited set of messages you're trying to deal with):
if (field_name == "joint1")
result = msg.joint1;
else if (field_name == "joint2")
result = msg.joint2;
...