473,836 Members | 1,935 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 4370
"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******** ************@we ber.videotron.n et...
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
16248
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 integer? Or Is it a reference to a pointer to a constant integer? What is being constant in this case? The pointer or the integer being pointed? How about int * const & ? Is this a reference to a constant pointer to an integer? Or
6
2618
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 breaking any software using the old API. The implementation looks like wxTree wxTreeListMainWindow::GetLastChild (const wxTree& item, long& cookie) const {
12
2627
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
1887
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 AreaSet &CObeyFile::AreaSet () const' r_areaset.h:197: changes meaning of `AreaSet' from `class AreaSet'
3
2272
by: Juha Nieminen | last post by:
Consider this code: void foo(int& i) { i += 10; } int main() { int a = 1;
6
5596
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 normal functions, not operators. I keep changing these to just have the plain old type, which is more efficient (I'm using embedded systems) and less obtuse. I'm puzzled why this one programmer insisted on odd style everywhere. Maybe he's just...
0
9812
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9658
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10533
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9362
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7775
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6975
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5644
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5813
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
4003
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.