Interesting table courtesy of my colleague Simon Locke about different possibilities of using const along with pointers and references.
Definition | Read-only | Ownership passed | Allows NULL |
Type& | No | No | No |
const Type& | Yes | No | No |
Type* | No | Yes | Yes |
const Type* | Yes | Yes | Yes |
Type* const | No | No | Yes |
const Type* const | Yes | No | Yes |
The definition field is the parameter being passed to a function or a return from the function. For example you can see an example here of the first definition of 'Type&'.
No comments:
Post a Comment