I\'m just learning C++ and from all the example code I have looked at over the past few days I am having a hard time understanding where the pointer should be placed.
<
Algough *
is sometimes placed next to the variable it really does belong to the type declaration. So the following:
SomeType *x, *y;
really means
SomeType *x;
SomeType *y;
The same goes with &
. Additionally *
, const
and &
are applied in the order of their proximity to the declared type. For example:
const SomeType * const *&x = ...;
would mean: reference to pointer to a const pointer to const SomeType. const
can be placed both before and after the type name. The const
before the type is applied before all the modifiers after the type. Also note that this is not allowed:
const SomeType const x = ...;
as it would essentially mean const const SomeType
, which doesn't make much sense.