Pergunta

I'd like to make my class object dynamically configurable by allowing user to specify a list of parameter strings and for each of those parameter strings, I'd like my class object to have a separate variable.

The user can specify any number of parameter strings and so, the class object should have a corresponding number of variables. I'd like to do this without having to define those variables as a part of a vector but I'm not sure if and how this can be done since all class variables are defined explicitly in the class code.

For example, let's say we want the variables to be "float userVar_${parameter}". If the user specifies N configurations 1,2,3,...,N in the config file, the class object should have N private variables userVar_1, userVar_2, userVar_3, ..., userVar_N

Thank you for your time!

Foi útil?

Solução

C++ is a statically typed language. You cannot change the type of a variable nor introduce new types at runtime. And your intention involves both.

So no, it's not possible.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top