I think you actually need something very different, but to give you an idea just how complex this task is, this something that would in part solve this problem:
template <class T>
class Property {
std::string name_;
T value_;
public:
Property(const std::string& name, const T& value) : name_(name), value_(value) {}
const T& get() const {return value_;}
void set(const T& value) { value_ = value; }
std::string name() const { return name_; }
};
struct student {
Property<int> rollnumber;
Property<int> mark1("mark1", 0);
Property<int> mark2("mark2", 0);
student(int roll, int m1, int m2)
: rollnumber("rollnumber", roll)
, mark1("mark1", m1)
, mark2("mark2", m2)
{
}
}
int main() {
Property<student> Stud("Stud", student(3, 5, 2));
...
return 0;
}
This defines your structure with derived types that contain the names of the variables along with their values. Then you have to set up some lookup mechanism, e. g. a map, to store each value. Then you need to parse the string you use to retrieve a value ("Stud->rollnumber"), split it up into its constituent parts ("Stud" and "rollnumber"), and then retrieve the corresponding values from your map. To make matters worse, you actually have to implement that retrieve function in your student class as well.
I do not think this is what you need at all, but until you tell us what the purpose of all this is, that is the best I can suggest.