469,156 Members | 2,190 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,156 developers. It's quick & easy.

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 4192
"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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by CoolPint | last post: by
6 posts views Thread by Otto Wyss | last post: by
12 posts views Thread by zealotcat | last post: by
3 posts views Thread by Juha Nieminen | last post: by
6 posts views Thread by Darin Johnson | last post: by
1 post views Thread by Mortomer39 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.