lundi 26 février 2018

In c++11, how can auto distinguish short from long at compile time?

I'm excited to start using auto variables in my C++ programs. I know that "auto" variables use template rules to deduce variable types, but I'm confused about how that works for numeric types. For example, suppose I have

auto foo = 12;

The type for foo could reasonably be int or even unsigned char. But suppose later in my program, I do some math and assign foo a value of 4 billion. At that point, I would want foo to have type unsigned int or perhaps long. How can compilers anticipate values that will be assigned later in the program?

Aucun commentaire:

Enregistrer un commentaire