My trick for this one is that 'const' applies to whatever it comes directly after (with one exception, on which more shortly). For instance:
int const* foo - foo is a pointer to const int int * const bar - bar is a const pointer to int int const * const baz - baz is a const pointer to const int
The one exception is that if there's an empty string to the left of 'const', then 'const' applies to whatever token is directly to the right of it. Thus, int const* foo and const int* foo are both pointers to const int.
This also applies to const functions, where you can end up with crazy stuff like
const int*const Method3(const int*const&)const;
as described here (http://duramecho.com/ComputerInformation/WhyHowCppConst.html). This function takes a const reference to a pointer to const int, returns a const pointer to const int, and can't modify the object that it's a method of.
I'd personally write that declaration as int const * const Method3(int const * const &Param)const; just to make it easier to follow, but when I'm not doing something that awkward-looking, I tend to put the 'const' first, just like most people. It's probably not good style though.
no subject
int const* foo - foo is a pointer to const int
int * const bar - bar is a const pointer to int
int const * const baz - baz is a const pointer to const int
The one exception is that if there's an empty string to the left of 'const', then 'const' applies to whatever token is directly to the right of it. Thus, int const* foo and const int* foo are both pointers to const int.
This also applies to const functions, where you can end up with crazy stuff like
const int*const Method3(const int*const&)const;
as described here (http://duramecho.com/ComputerInformation/WhyHowCppConst.html). This function takes a const reference to a pointer to const int, returns a const pointer to const int, and can't modify the object that it's a method of.
I'd personally write that declaration as int const * const Method3(int const * const &Param)const; just to make it easier to follow, but when I'm not doing something that awkward-looking, I tend to put the 'const' first, just like most people. It's probably not good style though.