How & work here?

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
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/
A increment(int) will also return an A object. I don't see the difference.
L B wrote:
[...] it returns a reference to an existing and persistent A object.
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
Topic archived. No new replies allowed.