Messages Order

  • + 0 comments
    class Message {
        int currId;
        string text;
    public: 
        Message() : currId{0}, text{} {}
        Message(int id, const string &msgText) : currId{id}, text{msgText} {}
        
        const string& get_text() const {
            return text;
        }
        
        friend bool operator<(const Message &lhs, const Message &rhs)
        {
            return lhs.currId < rhs.currId;
        }
    };
    
    class MessageFactory {
        int msgId = 0;
    public:
        MessageFactory() {}
        Message create_message(const string& text) {
            return Message{msgId++, text};
        }
    };