473,498 Members | 1,819 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

const in function declarations

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 );

Jul 23 '05 #1
5 2137

TechCrazy wrote:
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-lit...rrectness.html

Jul 23 '05 #2
More:

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

Jul 23 '05 #3
TechCrazy wrote:
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.

Jul 23 '05 #4
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
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 );

Jul 23 '05 #5
TechCrazy wrote:
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.

Jul 23 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
3614
by: joe | last post by:
hi, after reading some articles and faq, i want to clarify myself what's correct(conform to standard) and what's not? or what should be correct but it isn't simply because compilers don't...
7
3778
by: johny smith | last post by:
Can someone please explain to me the difference between these two: function1( const int a) function2( int const a) Both seemed to compile, but what is the difference between the two above....
7
1696
by: Martin | last post by:
I've searched this newsgroup's archives but couldn't find any posts that provided any "rule of thumb" recommendations for use of const in function parameters. I appreciate there is no need for...
8
2645
by: Laurijssen | last post by:
What are the advantages of using const as often as possible in C? Does it help to declare integer function arguments as const? How about pointers and automatic const integers? const int...
5
1988
by: arun | last post by:
Hello Team, I have a question on const vs non const and object return vs non object return function and which one will be called ie. void foo(); vs void foo() const;
7
1514
by: James | last post by:
Hello, First off, I know this code will not compile and am not asking for someone to solve it for me. What I am asking is from the code below, how does one first define an array as a...
7
2212
by: lovecreatesbea... | last post by:
Shoud we declare non-pointer function parameters with const keywords? int main(void){ int f(const int i); int i; f(i); return 0; }
10
2152
by: subramanian100in | last post by:
The following is a beginner's question. Suppose TYPE1 and TYPE2 are two types for which suitable ctors and operator= are defined. Suppose I have class Test { TYPE1 mem1;
2
1879
by: Jim Langston | last post by:
In my function/method paramater list I try to keep constant correctness. I.E. I would use: int Foo( const char* a, int b ) instead of int Foo( char* a, int b ) My question reguards int b. ...
0
7126
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7005
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7168
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7210
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6891
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7381
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
4916
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3087
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1424
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.