Connecting Tech Pros Worldwide Forums | Help | Site Map

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

hoox2
Guest
 
Posts: n/a
#1: Jul 19 '05
void push_front(Node const*& head, int data);


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



Jakob Bieling
Guest
 
Posts: n/a
#2: Jul 19 '05

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


"hoox2" <xxx@sss.com> wrote in message news:bls38m$c0o5@rain.i-cable.com...[color=blue]
> void push_front(Node const*& head, int data);
>
>
> Can someone tell me what it means for "const*&"? A reference or a pointer?[/color]

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)


David B. Held
Guest
 
Posts: n/a
#3: Jul 19 '05

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


"hoox2" <xxx@sss.com> wrote in message news:bls38m$c0o5@rain.i-cable.com...[color=blue]
> void push_front(Node const*& head, int data);
>
>
> Can someone tell me what it means for "const*&"? A
> reference or a pointer?[/color]

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


Jonathan Mcdougall
Guest
 
Posts: n/a
#4: Jul 19 '05

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


> void push_front(Node const*& head, int data);[color=blue]
>
>
> Can someone tell me what it means for "const*&"? A reference or a pointer?[/color]

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


Howard
Guest
 
Posts: n/a
#5: Jul 19 '05

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



"Jonathan Mcdougall" <jonathanmcdougall@DELyahoo.ca> wrote in message
news:vWigb.50012$282.685877@weber.videotron.net...[color=blue][color=green]
> > void push_front(Node const*& head, int data);
> >
> >
> > Can someone tell me what it means for "const*&"? A reference or a[/color][/color]
pointer?[color=blue]
>
> 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'[/color]
makes[color=blue]
> me wonder about that.
>[/color]

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

[color=blue]
>
> Jonathan
>
>[/color]


Jonathan Mcdougall
Guest
 
Posts: n/a
#6: Jul 19 '05

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


> > > void push_front(Node const*& head, int data);[color=blue][color=green][color=darkred]
> > >
> > >
> > > Can someone tell me what it means for "const*&"? A reference or a[/color][/color]
> pointer?[color=green]
> >
> > A const reference to a pointer. The function probably reset your[/color][/color]
pointer[color=blue][color=green]
> > to 0, meaning it takes ownership of the object, though the name 'head'[/color]
> makes[color=green]
> > me wonder about that.
> >[/color]
>
> Nope...it's a reference to a pointer to a constant Node object, not a[/color]
const[color=blue]
> 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.[/color]

You're right, sorry.


Jonathan


hoox2
Guest
 
Posts: n/a
#7: Jul 19 '05

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


Thanks all of you for your valuable and helpful explanation.


Regards,


Ho


Closed Thread


Similar C / C++ bytes