Created
September 19, 2014 14:46
-
-
Save sergeant-wizard/8cfeffe9c92359cba602 to your computer and use it in GitHub Desktop.
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> | |
#include <unistd.h> | |
class myClass{ | |
public: | |
myClass(){ | |
std::cout << "constructor called" << std::endl; | |
} | |
~myClass(){ | |
std::cout << "destructor called" << std::endl; | |
} | |
myClass(const myClass& other){ | |
std::cout << "const copy constructor called" << std::endl; | |
} | |
myClass(myClass& other){ | |
std::cout << "copy constructor called" << std::endl; | |
} | |
}; | |
myClass func(){ | |
return myClass(); | |
} | |
int main(){ | |
myClass b(func()); | |
myClass c; | |
myClass d(b); | |
c = func(); | |
return 0; | |
} | |
/* | |
constructor called | |
constructor called | |
copy constructor called | |
constructor called | |
destructor called | |
destructor called | |
destructor called | |
destructor called | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment