Explain whether the Sales_data constructor that takes a string should be explicit. What are the benefits of making the constructor explicit? What are the drawbacks
belongs to book: C++ Primer|Stanley B.Lippman, Josee Lajoie, Barbara E.Moo|5th Edition| Chapter number:7| Question number:47
All Answers
total answers (1)
It should be `explicit`. Otherwise, code like
`item.combine("9-999-99999-9")`
will compile, but the code has no logical meaning.Making the constructor
`explicit`
will stop compiler from automatically converting one type to the class type, which makes the code same as anticipation.The drawback is we must call the constructor explicitly if we want to cover one type to the class type.