Is it possible to create a type alias for auto
? I've tried both using var = auto
and typedef auto var
, and both throw an error that it's not allowed. So is there a way?
No.
auto
is not a type.
It is a keyword that triggers type deduction.
For it to work, there needs to be some information for it to deduce from! That's why it works in a declaration with an initialiser.
If you really want to be able to write var
in your code to get the same effect, like in (say) JavaScript, you could write a macro:
#define var auto
This will make the "word" var
behave just like the "word" auto
.
But please, please, please don't do that. It will only make your code harder to understand by C++ developers, without actually providing any tangible benefit to anybody in return.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With