Ok... As I'm studying classes I'm confronted with this feature:
A constructor that can be called with a single argument defines an implicit conversion from the parameter type to the class type.
While I understand the concept, I have trouble understanding something else... Given the following 3 constructors and member function,
Code:
MyClass(const string &str = ""): name(str), value(0) { }
MyClass(istream &is): name(is), value(0) {}
MyClass(const string &str, int val): name(str), value(val) { }
int MyClass::do_something(const myClass &obj) const;
I know that only the two first constructors define an implict conversion.
So, if I pass a string to do_something(), the first constructor is used to convert it to a temporary MyClass. Whereas if I pass an istream object, it is the 2nd constructor the one being used to make the implicit conversion.
But why is that I'm being told the istream option is poor class design? Isn't it conceivable that I may want such behavior?