Note on the use of const.
If you put const on the right or left is a style thing. Peronally I always put it on the right. As there are a couple of corner cases (with typedef) were it does make a difference and I want to be consistent.
Note: cost always binds to the type on its left. unless it is the left-most part of a type declaration then it binds right. Read type right to left.
char const* str1; // const binds left to char => (char const)*
// Read as: pointer to 'const char'
char const *const str2; // const binds left => (char const) (* const)
// Read as: 'const pointer' to 'const char'
// From the C world (and it has leaked into C++) so a lot of people still us it
const char* str3; // const as left-most part binds right => (const char) *
// Read as: pointer to 'char const'
Basically str1 and str3 are identical. But the consistency of always thinking that const binds to the left makes it neater in my mind.
One place where it can make a difference is typedefs. This is because the typedef has already formed a type so any external const are applied to the typedef type as a whole thing (not as individual parts).
typedef char* String;
const String str4; // const is the left-most item so binds right.
// So you may expect this to be the same as str3
// unfortunately this is not correct as the typedef
// String a whole type so the const applies to `String`
// not to the char.
// Thus this is like const (char*)
// Which is the same as (char*) const
// Read: const 'pointer to char' so once set the pointer
// can not be moved.
// If on the other hand you never put const in the left-most position then
// this problem never even comes up.
So two reasons not to put const as the left-most part of the type.