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

formatting - SAS SQL Datepart function returning odd values -

c++ - Apple Mach-O Linker Error(Duplicate Symbols For Architecture armv7) -

php - Yii 2: Unable to find a class into the extension 'yii2-admin' -