Why NRVO is not applied here?
问题 NRVO is not applied when I run this code in VS2010. #include <stdio.h> class A { public: A() { printf( "I am in constructor\n" ); } A(const A& a) { printf( "I am in copy constructor\n" ); } ~A() { printf( "I am in destructor\n" ); } int i; }; A f(int j) { A a; if ( j ) return a; a.i = j; return a; } int main() { A a; a = f(5); } Edit: this has something to do with the destructor. When I comment out its line, NRVO is used. But why is this? 回答1: Why NRVO is not applied here? If this purely a