I have a fixture class Foo, but TEST_F(Foo, Bar) gives me error “no matching function for call to Foo::Foo()”. Why?
Google Test needs to be able to create objects of your test fixture class, so it must have a default constructor. Normally the compiler will define one for you. However, there are cases where you have to define your own: • If you explicitly declare a non-default constructor for class Foo, then you need to define a default constructor, even if it would be empty. • If Foo has a const non-static data member, then you have to define the default constructor and initialize the const member in the initializer list of the constructor. (Early versions of gcc doesn’t force you to initialize the const member. It’s a bug that has been fixed in gcc 4.
Related Questions
- I have a fixture class FooTest, but TEST_F(FooTest, Bar) gives me error "no matching function for call to FooTest::FooTest()". Why?
- I have a fixture class Foo, but TEST_F(Foo, Bar) gives me error "no matching function for call to Foo::Foo()". Why?
- Why does POV-Ray gives me an error No matching } in texture, material identifier found instead.?