Created
March 6, 2015 11:52
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> | |
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