[18.5] What's the difference between "Fred const* p ", "Fred* const p " and "Fred const* const p "?
You have to read pointer declarations right-to-left.
const X& x and X const& x are equivalent.
Fred const* p means "p points to a constant Fred": the Fred object can't be changed via p.Fred* const p means "p is a const pointer to a Fred": you can't change the pointer p, but you can change the Fred object via p.Fred const* const p means "p is a constant pointer to a constant Fred": you can't change the pointer p itself, nor can you change the Fred object via p.
沒有留言:
張貼留言