473,569 Members | 2,634 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 14308
"Marcin Kalicinski" <ka****@poczta. onet.pl> wrote in message
news:Tr******** **********@news fe4-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 "*",specifi es a const variable that is
referenced by a.
2.int * const a=&b;
when "const" on the right "*",specifi es a const pointer.

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

1,const int * a=&b;
when "const" on the left "*",specifi es a const variable that is
referenced by a.
2.int * const a=&b;
when "const" on the right "*",specifi es 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
9386
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. If i make another constructor with parameter const char*, how can i call the constructor with the const string& ? I tried
19
6815
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
2169
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 bug in this function with the GetLength call whose results are sent to the sub-call to Concatenate. So I added the following and it asserts on...
1
1712
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 * const &szFoo". I usually just use "char *pszFoo" whenever I want to pass a string, or maybe "const char *pszFoo" if I know that I won't modify it....
6
10007
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 hoped I could solve, and I couldn't. Some code he's using, written in 1999, that compiled fine in 1999, no longer does in 2006 with g++ 4. This...
5
8802
by: Jae | last post by:
Real(const string &fileName) { FILE * myInputFile = fopen(fileName, "rt"); ..... fclose(myInputFile);
2
10863
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 think for a sec. At first I read it as converting a 'const char *' to a 'std::string *' void f(const std::string &s) { std::cout << s.size() <<...
2
3431
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 stack and the parameter will refer to this object. Is this correct? Does this mean if a constructor of a class has a string reference parameter, the...
2
1716
by: dolphin | last post by:
Why should we use fun(const Class &B) instead of fun(Class &B)?
0
7701
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
1
7677
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
6284
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5514
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5219
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3653
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3643
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2115
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 we have to send another system
0
940
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.