Quote:I would have been surprised if that compiled, since no constructor is made for type double!
There is an implicit promotion from int to double. This code should compile.
I did not know that was possible. I would be less surprised, in this shown case though, since I can understand implicit casting from int to double.
Quote:But from a POD (plain old datatype) to an object, via a constructor, I was surprised.
Single parameter constructors are known as conversion constructors. They are the counterpart of conversion operators.
Quote:By the way, I believe this property may only be "nested" a couple times (only a couple constructor levels down).
The implicit conversion chain can only contain one user-defined conversion.
Quote:@Anonymous Poster: Yep, that 'explicit' keyword is good to know! Thanks to the posters here for letting me know about it!
Single-parameter constructors should be marked explicit unless you know you want them to act as conversion constructors.