Created
May 23, 2022 02:03
-
-
Save rahulbhadani/d39d2f17a204faaab836f638303a1498 to your computer and use it in GitHub Desktop.
Named Return Value Optimization
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
using namespace std; | |
class OBJECT | |
{ | |
public: | |
const char *a; | |
OBJECT() | |
{ | |
cout<<"Constructor"<<endl; | |
} | |
OBJECT(const char *ptr) | |
{ | |
cout<<"Constructor"<<endl; | |
} | |
OBJECT(OBJECT &obj) | |
{ | |
cout<<"copy constructor"<<endl; | |
} | |
OBJECT(OBJECT&& obj) | |
{ | |
cout<<"Move constructor"<<endl; | |
} | |
~OBJECT() | |
{ | |
cout<<"Destructor"<<endl; | |
} | |
}; | |
OBJECT func1() | |
{ | |
OBJECT obj; return obj; | |
} | |
int main() | |
{ | |
OBJECT object; | |
OBJECT obj1(func1()); //NRVO | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment