vec; And I want vec ...">

Specify the type of vector with a string

How do you specify a type with a string? I mean:

string s = "int";
Vector<s> vec;

And I want vec to be vector<int>. Is it possible?

I want to create a class in which the user can enter a string, and a vector with this type will be created.

+5
source share
2 answers

Impossible in C ++, at least not the way you want.

Templates are a compile-time concept, and user input is a runtime concept. Completely different, not miscible.

To do this, you need a dynamically typed language that is not C ++. It is statically typed.

+5
source

Is it possible?

++. boost - , boost::variant: vector .

+3

All Articles