how can I access a filed by just having that field's name stored in a string? e.g. I have function template, an object and a string passed to that function:
class MyClass
{
public:
MyClass(int data)
{
this->data = data;
}
private:
int data;
};
template <class T>
void foo(T& myobj, string property_name)
{
//do sth
cout << myobj.getval(property_name) << endl;
}
how can I do something like this?