Skip to content

Instantly share code, notes, and snippets.

@siteshwar
Created March 6, 2015 11:52
Show Gist options
  • Save siteshwar/b7e522d31274f4ed72f7 to your computer and use it in GitHub Desktop.
Save siteshwar/b7e522d31274f4ed72f7 to your computer and use it in GitHub Desktop.
#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