What is the recommended approach for updating an object after creation with a stream of data? I would like to avoid using a number of SetXX methods.
Say I have a class that looks like this;
class Model { public: Model(int, double, std::string); private: int a; double b; std::string c; }; One approach to solving this was adding operator;
friend Model& operator<<(Model&, std::stringstream&) The usage of the above code;
// create model Model model(...); // do stuff // update model later model << stream; This approach compile and runs.
Just wondering if this is a good approach and if it has any flaws \ limitations? Notice that most example online using operator<< use it differently than what I am doing above.
>>, so you do e.g.stream >> model, the way you get input from any other stream likestd::cin. Your way works, but it's unusual and will not be easy to understand or comprehend by others except yourself (and maybe not even yourself in a few months time). Can you please explain why you want it the opposite way of what it's normally done? What's the rationale?