473,402 Members | 2,050 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,402 software developers and data experts.

What does *& stand for

gpraghuram
1,275 Expert 1GB
Hi ,
In one of the code i saw a declartion like this
Expand|Select|Wrap|Line Numbers
  1. virtual void check(Base*& ptr);
  2.  
I cant make out what this *& means and this is ina c++ code
Can somebody throw some light on this
Raghuram
Aug 27 '07 #1
12 2756
hariharanmca
1,977 1GB
Hi ,
In one of the code i saw a declartion like this
Expand|Select|Wrap|Line Numbers
  1. virtual void check(Base*& ptr);
  2.  
I cant make out what this *& means and this is ina c++ code
Can somebody throw some light on this
Raghuram

It may be a Virtual pointer declaration (but i am not sure about that).
Aug 27 '07 #2
JosAH
11,448 Expert 8TB
Hi ,
In one of the code i saw a declartion like this
Expand|Select|Wrap|Line Numbers
  1. virtual void check(Base*& ptr);
  2.  
I cant make out what this *& means and this is ina c++ code
Can somebody throw some light on this
Raghuram
Base: the type
Base*: a pointer to the type
Base*&: a reference to a pointer of the type
ptr: this is the name of the parameter.

It's a virtual member function with a parameter as decsribed above, and it
doesn't return anything (void).

kind regards,

Jos
Aug 27 '07 #3
hariharanmca
1,977 1GB
Base: the type
Base*: a pointer to the type
Base*&: a reference to a pointer of the type
ptr: this is the name of the parameter.

It's a virtual member function with a parameter as decsribed above, and it
doesn't return anything (void).

kind regards,

Jos
okay, Good to know. But is it possible to explain with any small example?

Thank you.
Aug 27 '07 #4
gpraghuram
1,275 Expert 1GB
Base: the type
Base*: a pointer to the type
Base*&: a reference to a pointer of the type
ptr: this is the name of the parameter.

It's a virtual member function with a parameter as decsribed above, and it
doesn't return anything (void).

kind regards,

Jos
I think i shuld have put my question more clearly.
I have doubt only about the *& in the parameter.
How it can be described?

Raghuram
Aug 27 '07 #5
gsi
51
Hi,

It depends on the context used,

1. When used in a lvalue or rvalue context the reference and dereference operator's cancel out each other
eg. *&b = *&a; //same as a=b

2. When used in as a function argument same as above, cancel out each other,
eg, foo(*&a);//function call same as foo(a);

3. When used in as a function parameter, indicates that the pointer argument from a caller is taken in as a reference.

eg, virtual void check(Base*& ptr); // check takes in a Base pointer as a reference.

Thanks,
gsi.
Aug 27 '07 #6
I think i shuld have put my question more clearly.
I have doubt only about the *& in the parameter.
How it can be described?

Raghuram
in this context it means that parameter to your function can be treated as a pointer for any given purpose with the added value that any change made to it within function will be reflected outside as well. example:

Expand|Select|Wrap|Line Numbers
  1. void f(char*& str) { 
  2.    str = new char[10]; 
  3.    strcpy(str,"hello"); 
  4. }
  5.  
  6. void g() {
  7.    char* my_str = NULL;
  8.    f(my_str);
  9.    cout << my_str << endl;
  10.    delete[] my_str;
  11. }
  12.  
calling g() will print: hello
since the pointer my_str was changed within f()
Aug 27 '07 #7
JosAH
11,448 Expert 8TB
I think i shuld have put my question more clearly.
I have doubt only about the *& in the parameter.
How it can be described?

Raghuram
Did you actually *read* my reply? It exactly describes what '*&' means in that
particular context.

kind regards,

Jos
Aug 27 '07 #8
JosAH
11,448 Expert 8TB
okay, Good to know. But is it possible to explain with any small example?

Thank you.
Nah, it's just a reference to a pointer instead of a pointer value, call by value vs
call by rereference and all that. The fact that a (reference of) a pointer is passed
doesn't add anything new or interesting to those two parameter passing methods.

kind regards,

Jos
Aug 27 '07 #9
hariharanmca
1,977 1GB
Nah, it's just a reference to a pointer instead of a pointer value, call by value vs
call by rereference and all that. The fact that a (reference of) a pointer is passed
doesn't add anything new or interesting to those two parameter passing methods.

kind regards,

Jos
Just asking to remember my self.
It's okay, But i got it in #7.
Aug 27 '07 #10
gpraghuram
1,275 Expert 1GB
Jos,
i understod fully after reading the example.

Thanks jos,agvaniya and gsi for a good explanation.

Thanks a lot
Raghuram
Aug 28 '07 #11
arunmib
104 100+
Hi,

It depends on the context used,

1. When used in a lvalue or rvalue context the reference and dereference operator's cancel out each other
eg. *&b = *&a; //same as a=b

2. When used in as a function argument same as above, cancel out each other,
eg, foo(*&a);//function call same as foo(a);

Thanks,
gsi.
I am sorry, I am not able to follow completely.....Why do I need to do it this way? I mean there must be some purpose or advantage in some particular situation for using this way right... I am kind of lost :-(
Aug 28 '07 #12
Banfa
9,065 Expert Mod 8TB
I am sorry, I am not able to follow completely.....Why do I need to do it this way? I mean there must be some purpose or advantage in some particular situation for using this way right... I am kind of lost :-(
You don't need to do it that way most likely wouldn't want to. gsi is was merely giving an example of how the C++ interpreter could interpret those characters if it came across them.

It is a waste of characters and obsfucates (confuses) the code.
Aug 28 '07 #13

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: modemer | last post by:
I saw someone use the following code: void func(MyClass *& myCls) { myCls->test(); } // call func(): func(new MyClass);
47
by: ship | last post by:
Hi We need some advice: We are thinking of upgrading our Access database from Access 2000 to Access 2004. How stable is MS Office 2003? (particularly Access 2003). We are just a small...
5
by: John Creighton | last post by:
What does BCPL stand for is it one language or a family of languages. My bust guess it the B C Programming Languages. But that is just a short in the dark. I am also not sure what languages fall...
4
by: Greg | last post by:
Regarding extensibility, e.g. EnvDTE what does "DTE" stand for? -- Greg McPherran www.McPherran.com
4
by: DoomedLung | last post by:
What does this operator ">-" stand for or mean, as in... this.ver = navigator.appVersion; this.agent = navigator.userAgent; this.dom = document.getElementById ? 1 : 0; this.opera5 =...
669
by: Xah Lee | last post by:
in March, i posted a essay “What is Expressiveness in a Computer Language”, archived at: http://xahlee.org/perl-python/what_is_expresiveness.html I was informed then that there is a academic...
27
by: Dr J R Stockton | last post by:
Unicode U+00B1 is &plusmn; - a plus sign sitting on top of a minus sign, possibly visible as ""; "plus/minus", in ISO-7 coding. As Alan will no doubt remember, algebraic work requiring that...
3
by: james.kirin40 | last post by:
Hi everyone, I am using Python's re module to extract some data from html. The following code never returns, and I was wondering if someone can explain to me why. Is this a problem with my...
5
by: cmrhema | last post by:
Hi, I have the following example enum MaterialColors { Blue=1,Red=2,Yellow=4, Purple=Blue|Red,Green=Yellow|Blue,Orange=Red|Yellow, } class Program { static...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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,...
0
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
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 projectplanning, coding, testing,...

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.