[C ++] top and bottom const const

  As described above, the pointer itself is an object , it can point to another object. Thus, the pointer itself is not constant, and a pointer is not constant is two separate issues. Top level represented by name const (top-level const) pointer itself is a constant, expressed in terms underlying const (low-level const) the object pointer is a constant.

  More generally, the top layer may represent any object const are constants, data types that are applicable, such as arithmetic type, class, pointer or the like. And the bottom pointer const reference type and the like related to compliance. More specific, the pointer type may be a top layer may be the underlying const const, this apparent difference compared with other types:

    int I = 0 ;
     int * const p1 = & I;          // changing the value p1, which is a top const 
    const  int ci = 42 is ;           // can not change the value of ci, which is a top const 
    const  int * P2 = & ci ;         // allowed to change the value of p2, which is a bottom const 
    const  int * const P3 = p2;    // by dotted const const is the top, the bottom, on the left is const 
    const  int & CI = R & lt;           // for declarative referential that is the underlying const
View Code

 

Guess you like

Origin www.cnblogs.com/bootblack/p/11550101.html