Quick A: Because the default assignement operator knows only the type of your object, which it can get be calling the constructor.
Recently on SO:
What is the point of calling constructor with implicit conversion instead of assignment operator after an object is initalized?
There is no implicit
CBox::operator=(double), sobox = 2.0;has to create a temporaryCBoxobject. It's equivalent tobox = CBox(2.0);.Making your constructor
explicitdisallows the implicit conversion fromdoubletoCBox, so no appropriate assignment operator exists, and you get a compile error.

Add a Comment
Comments are closed.