First let me apologize if the question sounds vague. Few years ago I saw a syntax which I can't recall. It allows me to create a pointer to a struct member.
What I'm trying to achieve is to create a member in my DoComplexCalculation class which points to a specific member in SensorData struct. To allow me to create many instances of the class where each instance work on different member of the struct (selected in the Init function).
The class
class DoComplexCalculation
{
public:
void Init(std::string& which_member_to_work_on)
{
if (which_member_to_work_on == "Temperature")
// initialize pointer to a Temperature struct member with, how ?
else if (which_member_to_work_on == "Humidity")
// initialize pointer to a Humidity struct member with, how ?
}
void CalculateNow(const SensorData& sensorData)
{
int membertoworkon = // some syntax to select the member by the initialized pointer
}
// Pointer to struct member, what is the syntax ?
}
A struct with many integer members:
struct SensorData
{
int Temperature;
int Humidity;
.
.
.
}