So I know that C++ is strongly typed and was just wondering if there was any library (or any thing for that fact of the matter) that would allow you to make a variable that has no initial specific type开发者_如何学运维 like var in Python.
Take a look at boost::any
and boost::variant
.
Two main things come to mind:
BOOST_AUTO
- C++0x type inference
In the new C++11, there is the auto
keyword which no longer refers to automatic duration but rather type inference occurs. So you can do this:
auto index = 1; // index is inferred to be int
auto c = 'a' // c is inferred to be a char
精彩评论