You are viewing a single comment's thread. Return to all comments →
Message's id assignment should be handled by the factory.
class Message { public: Message() {} Message(string text, int id):msg_body(text), msg_id(id) {} const string& get_text() { return msg_body; } bool operator<(const Message& other) const { return this->msg_id < other.msg_id; } private: string msg_body; int msg_id; }; class MessageFactory { public: MessageFactory() {} Message create_message(const string& text) { msg_counter += 1; return Message(text, msg_counter); } private: int msg_counter = -1; };
Seems like cookies are disabled on this browser, please enable them to open this website
Messages Order
You are viewing a single comment's thread. Return to all comments →
Message's id assignment should be handled by the factory.