- {l Code}: {l Select All Code}
Obj* foo = new Obj;
stream >> foo;
I don't like these kind of constructions for non-"string-like" objects. Looks rather bug-catchy and overly complicated to me. The other way round (operator<<) is logical of course, to easily generate a string that describes the object.
Are there any good reasons and best practices to do it this way? Wouldn't it be better to use default constructors? Ctors that provide default values so that they can be used empty or alternatively with all parameters. Then stream into variables and call the ctor with these variables. One big advantage here is that IDE's, compilers and static analysers report mistakes here (e.g. forgetting to set a variable or setting in wrong order). But when moving the construction task to streams you don't have this feature.
And after all, in most cases we have to stream into variables first anyway instread of directly into the object: when the values need to go through functions (setters, parsers or modifiers or something).
Another problem I see here is the possible "re-streaming" of existing objects (not sure if this actually done currently somewhere in our code) instead of a proper destruction and re-construction. This cancels out all the object-orientation, if it's possible to avoid the c/dtors and just re-assign new values.
Problem number three is the complexity. IMHO it's confusing if you only see:
- {l Code}: {l Select All Code}
stream >> a >> b >> c >> d;
There's also the IDE's autocompletion missing: If you call the constructor it tells you what it needs, this is not possible for streams.
Any opinions here? Maybe I'm just not seeing the big advantage of the stream method.