473,387 Members | 1,897 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

const char *&

void f(const char *&text);

Is this a const reference to char * or a reference to const char *? And how
to write both of them?

thank you,
Marcin
Sep 11 '05 #1
3 14266
"Marcin Kalicinski" <ka****@poczta.onet.pl> wrote in message
news:Tr******************@newsfe4-win.ntli.net
void f(const char *&text);

Is this a const reference to char * or a reference to const char *?
And how to write both of them?


You read from right to left, so it is a reference to a pointer to const
char. All references are const in the sense that you cannot "reseat" them to
refer to a different object. Your only choices in the present context are
between

1. a reference to a pointer to const char, as above,

const char *&text

2. a reference to a const pointer to char, which is

char *const &text

3. a reference to a const pointer to const char, which is

const char *const &text

Note that const char in 1. and 3. is the same as char const

--
John Carson

Sep 11 '05 #2
1,const int * a=&b;
when "const" on the left "*",specifies a const variable that is
referenced by a.
2.int * const a=&b;
when "const" on the right "*",specifies a const pointer.

Sep 12 '05 #3
je****@56.com wrote:

1,const int * a=&b;
when "const" on the left "*",specifies a const variable that is
referenced by a.
2.int * const a=&b;
when "const" on the right "*",specifies a const pointer.


What about

int const * a = &b;

?

The thing is: Your 'rule' is mighty complicated.
Much simpler:

const always works on the thing to its left.
Unless const is the leftmost specifier, in which case
it works on the thing immediatly to its right.

So, in

const int * a

the const works on the thing immediatly to its right:
It is the int, that is const

int * const a

const is not the leftmost specifier, thus it works on the thing
to its left: it is the pointer that is const.

int const * a

const is not the leftmost specifier, thus it works on the thing
to its left: it is the int that is const.
--
Karl Heinz Buchegger
kb******@gascad.at
Sep 12 '05 #4

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

Similar topics

5
by: selder21 | last post by:
Hello, I have a class with constructor taking a const string&. Now i want to call this constructor with a string literal. Because this is of type char* there are overload resolution conflicts....
19
by: Thomas Matthews | last post by:
Hi, Given a structure of pointers: struct Example_Struct { unsigned char * ptr_buffer; unsigned int * ptr_numbers; }; And a function that will accept the structure:
2
by: TonyM | last post by:
Q: Is there a good way to overcome this apparent bug without modifying the mfc code? ___________________________________ Info: Although it is NOT a good idea, I seemed to have perhaps located a...
1
by: Kip | last post by:
Greetings, Could anyone explain to me how the parameter type works here? I am also interested in the technical details of what is actually happening on the stack. I have never seen a "char *...
6
by: Geoffrey S. Knauth | last post by:
It's been a while since I programmed in C++, and the language sure has changed. Usually I can figure out why something no longer compiles, but this time I'm stumped. A friend has a problem he...
5
by: Jae | last post by:
Real(const string &fileName) { FILE * myInputFile = fopen(fileName, "rt"); ..... fclose(myInputFile);
2
by: pookiebearbottom | last post by:
Just looking for opinion on which of the 3 methods below people use in their code when they convert a 'const char *' to a 'const std::string &' came across #3 in someone's code and I had to...
2
by: ragged_hippy | last post by:
Hi, If I have a method that has string reference as a parameter, what happens if I pass a const char* variable to this method? One thought is that a temporary string will be created in the...
2
by: dolphin | last post by:
Why should we use fun(const Class &B) instead of fun(Class &B)?
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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
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...

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.