Point of declaration in C++

 

For the latest documentation on Visual Studio 2017, see Visual Studio 2017 Documentation.

For the latest documentation on Visual Studio 2017, see Point of declaration in C++ on docs.microsoft.com. A name is considered to be declared immediately after its declarator but before its (optional) initializer. (For more information on declarators, see Declarators.)

Consider this example:

// point_of_declaration1.cpp  
// compile with: /W1   
double dVar = 7.0;  
int main()  
{  
   double dVar = dVar;   // C4700  
}  

If the point of declaration were after the initialization, then the local dVar would be initialized to 7.0, the value of the global variable dVar. However, since that is not the case, dVar is initialized to an undefined value.

Scope

Show: