Is it possible to change the way of declaring variables and for it to accept any type of variable with c++ so something like this:
int main()
{
declare x = "Hello World!"
declare y = 1.2
}
Is it possible to change the way of declaring variables and for it to accept any type of variable with c++ so something like this:
int main()
{
declare x = "Hello World!"
declare y = 1.2
}
With C++11 and newer, you can use auto
. See https://en.cppreference.com/w/cpp/language/auto for more info.
With C++17 and newer, you can use std::any
. This is more useful if you are loading a std::vector with arbitrary data.
However, in my experience as a software engineer, too much auto/any usage can lead to unclear code.