There's a bit of a nasty trick you can perform with arrays and references which can mimic the effect of modifying different data members of a class/struct at runtime.
Given a simple struct like the following
struct person
{
std::string forename;
std::string surname;
std::string telephone;
std::string postcode;
};
Here, there's no safe nor portable way to maintain the names in the struct as well as being able to switch between them at compile time
One possible way around this is to stick all the data members in an array
struct person
{
std::string vars[4];
};
but that loses the nice, comfortable member names which are important for readability.
A common solution in C is to use an enum to index different members in a struct, but this is hardly elegant
struct person
{
std::string vars[4];
};
enum { forename , surname , telephone , postcode };
void func()
{
person my_person;
my_person.vars[forename] = "John";
}
A cleaner solution is to assign references to each position in the array. which makes the existence of the array all but invisible, except for those situations when you need to switch between data members at runtime
struct person
{
std::string vars[4];
std::string& forename;
std::string& surname;
std::string& telephone;
std::string& postcode;
person() : forename(vars[0]) ,
surname(vars[1]) ,
telephone(vars[2]) ,
postcode(vars[3])
{}
};
I'd still question as to exactly why you feel need to switch between data members at runtime, but references are a cleaner solution than macros at least.