次の方法で共有


Point of declaration in C++

 

The latest version of this topic can be found at Point of declaration in C++.

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.

See Also

Scope