Re: I can't understand this "const*&am p;" stands for?
"hoox2" <xxx@sss.com> wrote in message news:bls38m$c0o 5@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.
Re: I can't understand this "const*&am p;" stands for?
"hoox2" <xxx@sss.com> wrote in message news:bls38m$c0o 5@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
Re: I can't understand this "const*&am p;" 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.
Re: I can't understand this "const*&am p;" stands for?
"Jonathan Mcdougall" <jonathanmcdoug all@DELyahoo.ca > wrote in message
news:vWigb.5001 2$282.685877@we ber.videotron.n et...[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.
Re: I can't understand this "const*&am p;" 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]
Comment