cplusplus
.com
TUTORIALS
REFERENCE
ARTICLES
FORUM
C++
Tutorials
Reference
Articles
Forum
Forum
Beginners
Windows Programming
UNIX/Linux Programming
General C++ Programming
Lounge
Jobs
Forum
General C++ Programming
How & work here?
How & work here?
Jun 25, 2011 at 7:49pm UTC
Encinaar
(2)
1
2
3
4
5
6
7
class
A {
int
x;
public
: A& increment(
int
); };
I did not understand how does & work here. Can someone explain it and give a simple example to better understand the function of & here?
Last edited on
Jun 25, 2011 at 7:49pm UTC
Jun 25, 2011 at 7:50pm UTC
LB
(13399)
It means that instead of returning a temporary copy of an A object, it returns a reference to an existing and persistent A object. More on references here:
http://www.cplusplus.com/doc/tutorial/functions2/
Jun 25, 2011 at 7:58pm UTC
Encinaar
(2)
A increment(
int
)
will also return an A object. I don't see the difference.
Jun 25, 2011 at 8:18pm UTC
R0mai
(730)
L B
wrote:
[...] it returns a
reference
to an existing and persistent A object.
Jun 25, 2011 at 8:23pm UTC
closed account (
zb0S216C
)
Instead of returning a new
A
instance, it returns the address of another existing
A
instance.
Why was I reported? o_0
Wazzak
Last edited on
Jun 25, 2011 at 9:03pm UTC
Topic archived. No new replies allowed.