Udostępnij za pośrednictwem


/Zc:auto (Deduce Variable Type)

The /Zc:auto[-] compiler option tells the compiler how to use the auto keyword to declare variables. If you specify the default option, /Zc:auto, the compiler deduces the type of the declared variable from its initialization expression. If you specify /Zc:auto-, the compiler allocates the variable to the automatic storage class.

/Zc:auto[-]

Remarks

The C++ standard defines an original and a revised meaning for the auto keyword. Before Visual C++ 2010, the keyword declares a variable in the automatic storage class; that is, a variable that has a local lifetime. Starting with Visual C++ 2010, the keyword deduces the type of a variable from the declaration's initialization expression. Use the /Zc:auto[-] compiler option to tell the compiler to use the original or revised meaning of the auto keyword.

The compiler issues an appropriate diagnostic message if your use of the auto keyword contradicts the current compiler option. For more information, see auto Keyword. For more information about conformance issues with Visual C++, see Compatibility and Compliance Issues in Visual C++.

To set this compiler option in Visual Studio

  1. Open the project's Property Pages dialog box. For details, see Working with Project Properties.

  2. Click the Configuration Properties node.

  3. Click the C/C++ node.

  4. Click the Command Line node.

  5. Add /Zc:auto or /Zc:auto- to the Additional options: pane.

See Also

Reference

/Zc (Conformance)

auto Keyword