By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,290 Members | 1,666 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,290 IT Pros & Developers. It's quick & easy.

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

P: n/a
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
Share this Question
Share on Google+
6 Replies


P: n/a
"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

P: n/a
"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

P: n/a
> 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

P: n/a

"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

P: n/a
> > > 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

P: n/a
Thanks all of you for your valuable and helpful explanation.
Regards,
Ho
Jul 19 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.