Skip to content

Instantly share code, notes, and snippets.

@TyounanMOTI
Created January 23, 2012 16:05
Show Gist options
  • Save TyounanMOTI/1663990 to your computer and use it in GitHub Desktop.
Save TyounanMOTI/1663990 to your computer and use it in GitHub Desktop.
#include <gtest/gtest.h>
enum {
CONSTRUCTOR,
COPY_CONSTRUCTOR,
};
class Bar
{
public:
explicit Bar(const int b) : a(CONSTRUCTOR) {};
int a;
private:
Bar(const Bar& bar) : a(COPY_CONSTRUCTOR) {};
};
class Foo
{
public:
Foo() : bar(0) {};
Bar bar;
};
TEST(ConstructorTest, FooCallsConstructorOfBar) {
Foo foo;
EXPECT_EQ(CONSTRUCTOR, foo.bar.a);
}
@TyounanMOTI
Copy link
Author

in following case, compile fails because Foo calls Bar's private copy constructor.
line 22: Foo() : bar(Bar(0)) {}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment