title: Unable to update the value of field inside class
body: <p>This function removes the expired messages from the messages container</p>
  
  <pre><code>void Broker::removeExpiredMessages(){
      while(true){
          std::this_thread::sleep_for(std::chrono::milliseconds(1000));
          messageMut.lock();
          std::cout&lt;&lt;Broker::getMessages().size()&lt;&lt;std::endl;
          for(auto&amp; i : Broker::getMessages()){
              if(i.second.getHeader().expireAfter &lt;= 0){
                  std::cout&lt;&lt;"del"&lt;&lt;std::endl;
                  Broker::getMessages().erase(i.first);
              }
             else
               i.second.getHeader().setExpireAfter(i.second.getHeader().getExpireAfter()-1);
          }
          messageMut.unlock();
      }
  }
  </code></pre>
  
  <p><code>Message.hpp</code></p>
  
  <pre><code>class Message{
  public:
      struct Header{
          std::string time;
          int expireAfter;
          std::string topicName;
  
          int getExpireAfter() const {
              return expireAfter;
          }
  
          void setExpireAfter(int expireAfter) {
              this-&gt;expireAfter = expireAfter;
          }
  
          const std::string&amp; getTime() const {
              return time;
          }
  
          void setTime(const std::string &amp;time) {
              this-&gt;time = time;
          }
  
          const std::string&amp; getTopicName() const {
              return topicName;
          }
  
          void setTopicName(const std::string &amp;topicName) {
              this-&gt;topicName = topicName;
          }
      };
      Message(){}
      void setPayload(std::string _payload){
          this-&gt;payload = _payload;
      }
      std::string getPayload()const{
          return this-&gt;payload;
      }
  
      void setHeader(const std::string&amp; _time, const int _expireAfter, const std::string _topicName){
          this-&gt;header.setExpireAfter(_expireAfter);
          this-&gt;header.setTime(_time);
          this-&gt;header.setTopicName(_topicName);
      }
  
      Header getHeader()const{
          return this-&gt;header;
      }
  
  private:
      Header header;
      std::string payload;
  };
  </code></pre>
  
  <p><code>Broker.hpp</code></p>
  
  <pre><code>class Broker{
  public:
      static bool isSubscriberLoopRunning;
      Broker(){std::cout&lt;&lt;"Broker()"&lt;&lt;std::endl;}
      static std::queue&lt;const char*&gt;&amp; getMessageQueue() {
          return messageQueue;
      }
  
      static std::unordered_map&lt;const char*, Message&gt;&amp; getMessages() {
          return messages;
      }
  
      static std::vector&lt;Subscriber&gt;&amp; getSubscriberList() {
          return subscriberList;
      }
  
      static void pushNewSubscriber(Subscriber&amp;);
      static void receiveMessageFromPublisher(const Message&amp;);
      static void sendToSubscriber();
      static void removeSubscriber(const Subscriber&amp;);
      static void removeExpiredMessages();
  private:
      static std::unordered_map&lt;const char*,Message&gt; messages;
      static std::queue&lt;const char*&gt; messageQueue;
      static std::vector&lt;Subscriber&gt; subscriberList;
  };
  </code></pre>
  
  <p>I m trying to make messaging system and I have a Broker as middleware for subscriber and publisher to share a messages, messages are stored in <code>unordered_set&lt;const char*,Message&gt; messages</code>.One feature of broker is that it automatically deletes the expired message, for this I have made a function running in a seperate thread detached from its parent thread.</p>
  
  <p>My problem is it is not removing the messages whose expiration time has come, because the <code>expireAfter</code> variable is not decrementing even though I am doing it.I cannot understand why it not updating the value of the field <code>expireAfter</code>. </p>