473,233 Members | 1,402 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,233 software developers and data experts.

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 4336
"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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: CoolPint | last post by:
Can anyone clearly explain the difference between constant reference to pointers and reference to constant pointers? What is const int * & ? Is it a constant reference to a pointer to an...
6
by: Otto Wyss | last post by:
I've the following function declaration: wxTree GetLastChild (const wxTree& item, long& cookie) const; I'd like to make the cookie parameter optional, i.e. "long& cookie = ....", without...
12
by: zealotcat | last post by:
template <class T> inline T const& max (T const& a, T const& b) { // if a < b then use b else use a return a<b?b:a; } thanks very much!!
3
by: Alexander Farber | last post by:
Hi, does anyone have an idea, why do I get the following error (I have to use g++296 on RedHat Linux as compiler): In file included from r_dir.cpp:9: r_obey.h:262: declaration of `const...
3
by: Juha Nieminen | last post by:
Consider this code: void foo(int& i) { i += 10; } int main() { int a = 1;
6
by: Darin Johnson | last post by:
I keep running across that I'm maintaining that likes to define function parameters as "const char &" or "const int &", etc. Ie, constant reference parameters to a primitive type. This is for...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.