I thought that when you do:
Foo f1;
Foo f2 = f1;
The line Foo f2 = f1; calls the copy constructor of Foo and that it was equivalent to:
Foo f1;
Foo f2{f1};
However this seems not to be the case:
class Foo
{public:
Foo() {}
explicit Foo(const Foo& other) {}
};
int main()
{
Foo f1;
//Foo f2 = f1; // DOESN'T WORK IF COPY CONSTRUCTOR MADE EXPLICIT
Foo f2{ f1 }; // THIS WORKS WITH EXPLICIT
}
Why is this if there's no conversion? 'f1' is a Foo object, there shouldn't be a conversion. Why does it fail? Also in the following:
Foo funcReturningFoo()
{
Foo f;
return f; /* NO SUITABLE COPY CONSTRUCTOR IF MADE EXPLICIT */
}