Created
March 6, 2015 11:52
-
-
Save siteshwar/b7e522d31274f4ed72f7 to your computer and use it in GitHub Desktop.
This file contains 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> | |
class Foo { | |
public: | |
Foo() { std::cout << "Foo::Foo()" << std::endl; } | |
Foo(const Foo& y) { std::cout << "Foo::Foo(const Foo&)" << std::endl; } | |
}; | |
void func(const Foo& ref) { } | |
int main() | |
{ | |
Foo *tmp = new Foo(); | |
bool flag = true; | |
func(flag ? *tmp : Foo()); // This will invoke copy constructor | |
//func(*tmp); // This will not invoke copy constructor | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment