473,508 Members | 2,213 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

I can't understand this "const*&" stands for?

void push_front(Node const*& head, int data);
Can someone tell me what it means for "const*&"? A reference or a pointer?
Jul 19 '05 #1
6 4354
"hoox2" <xx*@sss.com> wrote in message news:bl*********@rain.i-cable.com...
void push_front(Node const*& head, int data);
Can someone tell me what it means for "const*&"? A reference or a pointer?


Both, sort of *g* Read everything from right to left: 'head' is a
reference to a pointer to a constant 'Node'. This means the passed pointer
can be modified by the function, but the object the pointer points to cannot
be modified.

hth
--
jb

(replace y with x if you want to reply by e-mail)
Jul 19 '05 #2
"hoox2" <xx*@sss.com> wrote in message news:bl*********@rain.i-cable.com...
void push_front(Node const*& head, int data);
Can someone tell me what it means for "const*&"? A
reference or a pointer?


Except for an initial const, these kinds of types should be
understood from left to right:

Node const x; // a const object of type Node
Node const* x; // a pointer to a const Node object
Node const* &x; // a reference to a pointer to a const Node

My guess is that push_front() is an operation that works
on lists, which is probably why it takes head by reference.
Since the function probably doesn't need to modify the
pointed-to Node object, it takes that as const. Since it
is probably going to modify the head pointer, it takes
that as non-const &.

Dave

---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.521 / Virus Database: 319 - Release Date: 9/23/2003
Jul 19 '05 #3
> void push_front(Node const*& head, int data);


Can someone tell me what it means for "const*&"? A reference or a pointer?


A const reference to a pointer. The function probably reset your pointer
to 0, meaning it takes ownership of the object, though the name 'head' makes
me wonder about that.
Jonathan
Jul 19 '05 #4

"Jonathan Mcdougall" <jo***************@DELyahoo.ca> wrote in message
news:vW********************@weber.videotron.net...
void push_front(Node const*& head, int data);
Can someone tell me what it means for "const*&"? A reference or a
pointer?
A const reference to a pointer. The function probably reset your pointer
to 0, meaning it takes ownership of the object, though the name 'head' makes me wonder about that.

Nope...it's a reference to a pointer to a constant Node object, not a const
reference.

The const keyword could go in front of the Node and it would be the same,
but otherwise read it from right-to-left to get:
reference-to-pointer-to-const-Node.

-Howard


Jonathan

Jul 19 '05 #5
> > > void push_front(Node const*& head, int data);


Can someone tell me what it means for "const*&"? A reference or a pointer?

A const reference to a pointer. The function probably reset your
pointer to 0, meaning it takes ownership of the object, though the name 'head'

makes
me wonder about that.


Nope...it's a reference to a pointer to a constant Node object, not a

const reference.

The const keyword could go in front of the Node and it would be the same,
but otherwise read it from right-to-left to get:
reference-to-pointer-to-const-Node.


You're right, sorry.
Jonathan
Jul 19 '05 #6
Thanks all of you for your valuable and helpful explanation.
Regards,
Ho
Jul 19 '05 #7

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

Similar topics

2
16224
by: CoolPint | last post by:
Can anyone clearly explain the difference between constant reference to pointers and reference to constant pointers? What is const int * & ? Is it a constant reference to a pointer to an...
6
2599
by: Otto Wyss | last post by:
I've the following function declaration: wxTree GetLastChild (const wxTree& item, long& cookie) const; I'd like to make the cookie parameter optional, i.e. "long& cookie = ....", without...
12
2571
by: zealotcat | last post by:
template <class T> inline T const& max (T const& a, T const& b) { // if a < b then use b else use a return a<b?b:a; } thanks very much!!
3
1830
by: Alexander Farber | last post by:
Hi, does anyone have an idea, why do I get the following error (I have to use g++296 on RedHat Linux as compiler): In file included from r_dir.cpp:9: r_obey.h:262: declaration of `const...
3
2253
by: Juha Nieminen | last post by:
Consider this code: void foo(int& i) { i += 10; } int main() { int a = 1;
6
5563
by: Darin Johnson | last post by:
I keep running across that I'm maintaining that likes to define function parameters as "const char &" or "const int &", etc. Ie, constant reference parameters to a primitive type. This is for...
0
7132
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
7336
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
7401
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
7063
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
7504
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
5059
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
1568
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 ...
1
773
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
432
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...

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.