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 this possible?
I want to make a class where the user can type in a string and a vector with that type will be created.
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 this possible?
I want to make a class where the user can type in a string and a vector with that type will be created.
Not possible in C++, atleast not the way you want.
Templates are a compile time concept, while user input is a runtime concept. Completely different, not mixable.
To make that work, you need a dynamically typed language, which C++ is not. It's statically typed.
Is this possible?
This is not possible in C++. If using boost is an option, consider creating a vector of boost::variant
objects instead: this way, your statically-typed vector
would be prepared to accept elements of different types.