Wednesday 5 August 2009

Const Pointer and References Table

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&NoNoNo
const Type&YesNoNo
Type*NoYesYes
const Type*YesYesYes
Type* constNoNoYes
const Type* constYesNoYes

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