deleted default constructor headache

c++

Solution

To fix your error. You need to make Foo::Foo() public.

class Foo
{
public:
    Foo() { }
};

Otherwise I do believe it is private.

Is this what your looking for?

Problem

My c++ book says this (lippman, c++ primer, fifth ed., p. 508): The synthesized default constructor is defined as deleted if the class ... has a const member whose type does not explicitly define a default constructor and that member does not have an in-class initializer. (emphesis mine) Why then does this code produce an error? ``` class Foo { Foo() { } }; class Bar { private: const Foo foo; }; int main() { Bar f; //error: call to implicitly-deleted default constructor of 'Bar' return 0; } ``` The rule above seems to indicate that it should not be an error, because Foo does explicitly define a default constructor. Any ideas?

Original source