vec; And I want vec ...">Geek Answers HandbookSpecify the type of vector with a stringHow 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.+5c ++ types vectorshizzle Dec 20 '11 at 18:59source share2 answersImpossible 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.+5Xeo Dec 20 '11 at 19:01source shareIs it possible?++. boost - , boost::variant: vector .+3dasblinkenlight 20 . '11 19:02More articles:which design is better for a client / server project with a lot of data exchange - c #C ++: how to create unsigned char from UTF-8 code point - c ++The server could not resume the transaction. Linq-To-SQL - sql-serverAnimated fragment when fragments are loaded from XML - androidwhere is the "window" object defined or created in firefox source code - javascriptHypercube with multidimensional vectors - c ++Installing PIL on OS X Lion (full noob) - pythonHABTM mongoid servo / servo - ruby-on-railsPython subprocess with arguments having multiple quotes - pythonFailed to create PIL on Mac OS X 10.7 Lion - pythonAll Articles
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?
vector<int>
I want to create a class in which the user can enter a string, and a vector with this type will be created.
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.
Is it possible?
++. boost - , boost::variant: vector .
boost::variant
vector