Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Compiler Issue with auto? Error: in a declarator-list 'auto' must always deduce to the same type

std::vector<int> vec;
auto i = vec.begin(), j = std::next(i);

Error: in a declarator-list 'auto' must always deduce to the same type

like image 523
David Avatar asked Oct 16 '12 20:10

David


People also ask

How to use auto type c++?

To use the auto keyword, use it instead of a type to declare a variable, and specify an initialization expression. In addition, you can modify the auto keyword by using specifiers and declarators such as const , volatile , pointer ( * ), reference ( & ), and rvalue reference ( && ).

Why auto is used in c++?

The auto keyword in C++ automatically detects and assigns a data type to the variable with which it is used. The compiler analyses the variable's data type by looking at its initialization. It is necessary to initialize the variable when declaring it using the auto keyword.

How to initialize auto variable in c++?

You can initialize any auto variable except function parameters. If you do not explicitly initialize an automatic object, its value is indeterminate. If you provide an initial value, the expression representing the initial value can be any valid C or C++ expression.


2 Answers

Compiles fine in g++ on Linux, so it appears to be a compiler bug. Probably this one.

like image 56
PherricOxide Avatar answered Sep 27 '22 21:09

PherricOxide


This appears to be a compiler error. See this link below. http://connect.microsoft.com/VisualStudio/feedback/details/728741 May already have been fixed judging by the comments in the link.

like image 29
bobestm Avatar answered Sep 27 '22 21:09

bobestm