Quick question

P

parag_paul

Sorry for aksing too many today ,

I have seen const char &strl;
where you cannot change str.

Is there a similar concept like,
char* const str ;
for references,

char const &str;

etc
If not , what is the reason for being so.
-Parag
 
V

Victor Bazarov

Sorry for aksing too many today ,

I have seen const char &strl;
where you cannot change str.

You cannot change what 'str' refers to because it's 'const'.
You cannot change 'str' itself because there is no syntax for
that (since 'str' is a reference).
Is there a similar concept like,
char* const str ;
for references,

char const &str;

Huh? That's not the same. 'char' here is const. When you
declare

char* const str;

'str' is const, not 'char'. 'char' there is actually non-const.

'etc' what?
If not , what is the reason for being so.

What is it exactly you need to know?

V
 
B

Brian Szmyd

Sorry for aksing too many today ,

I have seen const char &strl;
where you cannot change str.

Is there a similar concept like,
char* const str ;
for references,

char const &str;

etc
If not , what is the reason for being so. -Parag

I think what you're looking for is: char& str const

const always acts to the left, unless there is no left then to the right.

const char* == char const * != char* const
 
B

Brian Szmyd

On Fri, 02 Nov 2007 11:41:02 -0700, (e-mail address removed) wrote:

I think what you're looking for is: char& str const

const always acts to the left, unless there is no left then to the
right.

const char* == char const * != char* const

Oops...I posted that too quickly. char& str const makes no sense, you
const the type, not the name. str is never const, it's just a variable
name. the type "char" or "char*" is what is const.
 
V

Victor Bazarov

Brian said:
Oops...I posted that too quickly. char& str const makes no sense, you
const the type, not the name. str is never const, it's just a
variable name. the type "char" or "char*" is what is const.

Well, the syntax you were looking for is

char & const str

but it does not exists since references cannot have cv-qualifiers
because they are not objects.

The syntax (if it existed) would be just like

char * const str

(here 'str' is a constant pointer to [non-constant] char).

V
 

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

Forum statistics

Threads
473,764
Messages
2,569,566
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top