const in function declarations

T

TechCrazy

What do each of these mean? Thanks. I am incredibly confused.

char foo (const char * &p );
char foo (const char &* p );
char foo (const &char * p );

char foo (const char * const &p );
char foo (const char * &const p );
char foo (const char &* const p );
char foo (const &char * const p );

char foo (const& char * const &p );
char foo (const& char * &const p );
char foo (const& char &* const p );
char foo (const& char * const p );

char foo (const char& * const &p );
char foo (const char& * &const p );
 
D

damienk

TechCrazy said:
What do each of these mean? Thanks. I am incredibly confused.

char foo (const char * &p );
char foo (const char &* p );
char foo (const &char * p );

char foo (const char * const &p );
char foo (const char * &const p );
char foo (const char &* const p );
char foo (const &char * const p );

char foo (const& char * const &p );
char foo (const& char * &const p );
char foo (const& char &* const p );
char foo (const& char * const p );

char foo (const char& * const &p );
char foo (const char& * &const p );

See http://www.parashift.com/c++-faq-lite/const-correctness.html
 
T

TechCrazy

More:

char foo (char * const &p );
char foo (char * &const p );
char foo (char &* const p );
char foo (&char * const p );
 
R

Rolf Magnus

TechCrazy said:
What do each of these mean? Thanks. I am incredibly confused.

char foo (const char * &p );

The function takes a reference to a pointer to a constant character.
char foo (const char &* p );
Invalid.

char foo (const &char * p );
Invalid.

char foo (const char * const &p );

The function takes a reference to a constant pointer to a constant char.
char foo (const char * &const p );
Invalid.

char foo (const char &* const p );
Invalid.

char foo (const &char * const p );
Invalid.

char foo (const& char * const &p );
Invalid.

char foo (const& char * &const p );
Invalid.

char foo (const& char &* const p );
Invalid.

char foo (const& char * const p );
Invalid.

char foo (const char& * const &p );
Invalid.

char foo (const char& * &const p );

Invalid.
 
G

grahamo

Rule of thumb....

draw a line thru the "*", if the word "const" appears on LHS then
what's pointed to is const. If the word const appears on RHS, then
it's a constant pointer. If it appears on both sides, then both are
constants.

From Scott Meyers effective C++ book

G
 
R

Rolf Magnus

TechCrazy said:
More:

char foo (char * const &p );

The function takes a reference to a constant pointer to a char.
char foo (char * &const p );
Invalid.

char foo (char &* const p );
Invalid.

char foo (&char * const p );

Invalid.
 
G

Grant Schoep

(e-mail address removed) (grahamo) wrote in @posting.google.com:
Rule of thumb....

draw a line thru the "*", if the word "const" appears on LHS then
what's pointed to is const. If the word const appears on RHS, then
it's a constant pointer. If it appears on both sides, then both are
constants.

From Scott Meyers effective C++ book

G

Hah, I read "draw a line" before reading the rest and though, hey, thats
from Meyer's Eff. C++.

When I first saw this post, I was thinking, hmm. lets see. Its about that
time of year for a test in a computer programming class. Maybe like a final
or something. Entry level of course...

-grant
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,056
Latest member
GlycogenSupporthealth

Latest Threads

Top