Foo f = Foo(); // no matching function for call to 'Foo::Foo(Foo)' … huh?

后端 未结 10 2666
小鲜肉
小鲜肉 2021-02-19 20:13
class Foo
{
public:
    explicit Foo() {}
    explicit Foo(Foo&) {}
};

Foo d = Foo();

error: no matching function for call to \

10条回答
  •  终归单人心
    2021-02-19 20:35

    Your problem is in the instantiation. You don't need Foo d = Foo(); for a default constructor.

    Keep your class the same, but try this for instantiation:

    Foo d;
    

    In fact, you don't even need Foo d = Foo(arguments); for constructing with parameters. That should be like this:

    Foo d(arguments);
    

提交回复
热议问题