C++ Can I declare a Struct using a variable value as the Struct name? -



C++ Can I declare a Struct using a variable value as the Struct name? -

i have declared simple struct utilize in program. when go create variable based on struct in main program, name based on name have stored in variable.

is possible?

e.g. struct declared this:

struct mygreatstruct{ int foo; int fum; }

then later in program, user inputs name gets stored in variable called somevariable

and need utilize variable value name struct:

mygreatstruct somevariable;

use associative container e.g. std::unordered_map

example:

#include <iostream> #include <unordered_map> int main(int argc, char *argv[]){ std::unordered_map<std::string, mygreatstruct> vars; std::string var_name; std::cout << "input var name" << std::endl; std::cin >> var_name; vars[var_name].foo = 1; // using name user gave }

c++ struct

Comments

Popular posts from this blog

maven fortify plugin : Unable to load build session with ID XXXXX .. See log file for more details -

c# - Primavera WebServices does not return any data -

android - Display emoji panel with genymotion - keyboard/touch input? -