Skip to content

Commit 45c839d

Browse files
authored
Two syntaxes for initialising auto-typed variables
The initialisation expression can be an assignment but that means `a = b = 0`. The initialisation expression can involve `operator new` but it is not a separate case. Compare `auto a = new int;` and `auto a (new int);`. There is no initialisation statement inherently involving `operator new` (unlike in Visual Basic). The fact that a `for` loop involves an initialisation statement is a side note at best. This trivia fact is not specific to `auto`. The parenthesised "explanations" explained one unknown with another unknown. I replaced them with short examples.
1 parent b66ea6b commit 45c839d

1 file changed

Lines changed: 1 addition & 1 deletion

File tree

docs/cpp/auto-cpp.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ Conversion cases in which you might not want to use **`auto`**:
4040

4141
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 (**`&&`**). The compiler evaluates the initialization expression and then uses that information to deduce the type of the variable.
4242

43-
The initialization expression can be an assignment (equal-sign syntax), a direct initialization (function-style syntax), an [`operator new`](new-operator-cpp.md) expression, or the initialization expression can be the *for-range-declaration* parameter in a [Range-based `for` Statement (C++)](../cpp/range-based-for-statement-cpp.md) statement. For more information, see [Initializers](../cpp/initializers.md) and the code examples later in this document.
43+
The initialization expression can be passed using an assignment syntax (`auto int = 0;`) or a constructor syntax (`auto int (0);`). For more information, see [Initializers](../cpp/initializers.md) and the code examples later in this document.
4444

4545
The **`auto`** keyword is a placeholder for a type, but it is not itself a type. Therefore, the **`auto`** keyword cannot be used in casts or operators such as [`sizeof`](../cpp/sizeof-operator.md) and (for C++/CLI) [`typeid`](../extensions/typeid-cpp-component-extensions.md).
4646

0 commit comments

Comments
 (0)