When I declare my copy constructor as explicit, calling it using = instead of () doesn't compile. Here's my code:
class Base
{
public:
explicit Base(){cout<<__PRETTY_FUNCTION__<<endl;}
explicit Base(Base& b){cout <<__PRETTY_FUNCTION__<<endl;}
};
int main()
{
Base a;
Base b=a;
}
The compiler says:
error: no matching function for call to ‘Base::Base(Base&)’
If I change it to
Base b(a);
It compiles fine. I thought C++ considers these two styles of instantiations the same. If I remove the explicit keyword it does works both ways. I'm guessing there is some implicit conversion going on when I use =. So what am I missing here?