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 temporaryCBox
object. It's equivalent tobox = CBox(2.0);
.Making your constructor
explicit
disallows the implicit conversion fromdouble
toCBox
, so no appropriate assignment operator exists, and you get a compile error.
Add a Comment
Comments are closed.