FAQ 14.01 How should pointer declarations be read?

Pointer declarations should be read right to left.

If Fred is some type, then

  • Fred* is a pointer to a Fred (the * is pronounced "pointer to a").

  • const Fred* is a pointer to a Fred that cannot be changed via that pointer.

  • Fred* const is a const pointer to a Fred. The Fred object can be changed via the pointer, but the pointer itself cannot be changed.

  • const Fred* const is a const pointer to a Fred that cannot be changed via that pointer.

References are similar: read them right to left.

  • Fred& is a reference to a Fred (the & is pronounced "reference to a").

  • const Fred& is a reference to a Fred that cannot be changed via that reference.

Note that Fred& const and const Fred& const are not included in the second list. This is because references are inherently immutable: you can never rebind the reference so that it refers to a different object.



C++ FAQs
C Programming FAQs: Frequently Asked Questions
ISBN: 0201845199
EAN: 2147483647
Year: 2005
Pages: 566
Authors: Steve Summit

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net