-2

I want to make a function that has one parameter (a string that contains the name of a variable in my program) and returns the value that the variable stores.

Ștefan Neagu
  • 29
  • 2
  • 6

1 Answers1

4

Unfortunately, C++ doesn't provide a simple mechanism for reflection (the idea that the program can, at runtime, look up variable names by value or the like). You may need to consider using an alternate approach.

For example, you could make a std::unordered_map whose keys represent certain values that you'd like to look up and whose values are populated with the items you'd like to look up.

Hope this helps!

templatetypedef
  • 362,284
  • 104
  • 897
  • 1,065