Possible Duplicate:
Why copy constructor is not called in this case?
What are copy elision and return value optimization?
Can anybody explain to me why the following program yields output "cpy: 0" (at least when compiled with g++ 4.5.2):
#include<iostream>
struct A {
    bool cpy;
    A() : cpy (false) {
    }
    A (const A & a) : cpy (true) {
    }
    A (A && a) : cpy (true) {
    };
};
A returnA () { return A (); }
int main() {
    A a ( returnA () );
    std::cerr << "cpy: " << a.cpy << "\n";
}
The question arised when I tried to figure out seemingly strange outcome of this example: move ctor of class with a constant data member or a reference member
 
     
    