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.



Ownership passed

Allows NULL

const Type&YesNoNo
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