Why does C++ not allow multiple types in one auto statement? -- StackOverflow

Recently on SO:

Why does C++ not allow multiple types in one auto statement?

The 2011 C++ standard introduced the new keyword auto, which can be used for defining variables instead of a type, i.e.

auto p=make_pair(1,2.5);                   // pair<int,double>
auto i=std::begin(c), end=std::end(c);     // decltype(std::begin(c))

In the second line, i and end are of the same type, referred to as auto. The standard does not allow

auto i=std::begin(container), e=std::end(container), x=*i;

when x would be of different type. My question: why does the standard not allow this last line? ...

Add a Comment

Comments are closed.

Comments (0)

There are currently no comments on this entry.