Can C++ have "dynamic languages stuff"?

I haven't said dynamic variables because almost all people would think in int* a = new int;. I mean dynamic variables, like in Python:
1
2
a = 10
a = "im a string!" #no problem! 


There is any C++ library for that or even on standard?
Last edited on
If you're referring to dynamically typed variables, no.
C++11 supports the auto keyword, but the type still has to be known at compile time.

You could also choose to make a class which specifies the cast operator from any primitive or string.

1
2
3
GenericType a = 10;
GenericType b = "im a string"; // no problem!
auto c = 10.0;


However, that's the extent to which C++ will help you. If you'd like to use a scripting language, you can support it in C++. For instance, LUA will handle weak-typing and you can integrate this very easily with C++.

boost::any
boost::variant
@Caligulaminus you got the right answer. Thanks :)
Topic archived. No new replies allowed.