Connecting Tech Pros Worldwide Help | Site Map

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

 
LinkBack Thread Tools Search this Thread
  #1  
Old July 19th, 2005, 06:55 PM
hoox2
Guest
 
Posts: n/a
Default 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?



  #2  
Old July 19th, 2005, 06:55 PM
Jakob Bieling
Guest
 
Posts: n/a
Default 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)


  #3  
Old July 19th, 2005, 06:55 PM
David B. Held
Guest
 
Posts: n/a
Default 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


  #4  
Old July 19th, 2005, 06:56 PM
Jonathan Mcdougall
Guest
 
Posts: n/a
Default 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


  #5  
Old July 19th, 2005, 06:56 PM
Howard
Guest
 
Posts: n/a
Default 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]


  #6  
Old July 19th, 2005, 06:56 PM
Jonathan Mcdougall
Guest
 
Posts: n/a
Default 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


  #7  
Old July 19th, 2005, 06:56 PM
hoox2
Guest
 
Posts: n/a
Default Re: I can't understand this "const*&" stands for?

Thanks all of you for your valuable and helpful explanation.


Regards,


Ho


 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 220,840 network members.