Is it legal to hold reference/pointer to the return object value of a function?
<p>Is it legal to pass the return object of the function by value?
I have a function from <code>A::getA()</code> that returns an object by value.
Is it legal to reference this value in the same line, see the line
<code>b.processA(a.getA());</code></p>

<p>Please see my code below:</p>

<pre><code>class A
{
public:
    int a;
    std::list&lt;int*&gt; m_list;

    A(int a)
    {
        this-&gt;a =a;
    }

    A(A&amp; _a)
    {
        this-&gt;a =_a.a;
        m_list.push_back(&amp;a);
    }

    A getA()
    {
        A localA(20);
        localA.m_list.push_back(&amp;localA.a);
        return localA;
    }
};

class B
{
public:
    char b;

    B(char b)
    {
    }

    void processA(A&amp; a)
    {
            a.a = 1;
            processA2(a);
    }

    void processA2(A&amp; a)
    {
        a.a = 2;
    }
};

void main()
{
    B b('a');
    A a(11111);
    //************
    // IS THE FOLLOWING LINE LEGAL??
    // I mean, is it legal to pass the return object of the function by value
    //************
    b.processA(a.getA());
}
</code></pre>
