Content deleted Content added
OracleofTroy (talk | contribs) m Style - C++ programmers usually do not use "struct S s" when instantiating. |
m →Pointers and references: spread out argument list across lines for legability |
||
Line 22:
===Pointers and references===
For pointer and reference types, the syntax is slightly more subtle. A pointer object can be declared as a <code>const</code> pointer or a pointer to a <code>const</code> object (or both). A <code>const</code> pointer cannot be reassigned to point to a different object from the one it is initially assigned, but it can be used to modify the object that it points to (called the "pointee"). (Reference variables are thus an alternate syntax for <code>const</code> pointers.) A pointer to a <code>const</code> object, on the other hand, can be reassigned to point to another object of the same type or of a convertible type, but it cannot be used to modify any object. A <code>const</code> pointer to a <code>const</code> object can also be declared and can neither be used to modify the pointee nor be reassigned to point to another object. The following code illustrates these subtleties:
void Foo( int *ptr,
int const * ptrToConst, int *const constPtr, int const * const constPtrToConst ) {
int const i;
|