title: Call a method immediately after another one finished
body: <p>I have the following pseudocode as part of a C++ project:</p>
  
  <pre><code>class BasicSender
  {
  public:
       virtual void confirmation(int id) = 0;
       int sendMessage(string x)
       {
            Message x = createMessageFromString(x);
            if(! canSendMessage(m))
            {
                 MessageStore::storeMessageForLater(this, m); // just store it 
            }
            // *** HERE ***
            return m.messageId;
       }
  };
  
  void threadFunction()
  {
        while(1)
        {
              while(MessageStore::hasMessagesToBeSent())
              {
                    StoredMessage m = MessageStore.getNextUnsentMessage();
                    if(m.basicSender.sendStoredMessage(m.message))
                    {
                          m.confirmation(m.message.messageId);
                    }
              }
        }
  }
  </code></pre>
  
  <p>and the usage of it:</p>
  
  <pre><code>class ConcreteSender : public BasicSender
  {
      virtual void confirmation(int id)
      {
          cout &lt;&lt; "Yippe " &lt;&lt; id  &lt;&lt; " is sent";
      }
  };
  
  
  int main() {
      ConcreteSender a;
      int ID = a.sendMessage("test");
      ... other stuff
  }
  </code></pre>
  
  <p>And what I try to achieve:</p>
  
  <p>is it even remotely possible to call the <code>confirmation</code> for succesfully delivered messages method right after <code>sendMessage</code> finished (ie: it returned to the caller and the caller (in <code>main</code>) has the <code>ID</code> value). If I put the method call at the place <code>*** HERE ***</code> the virtual method will get called before <code>sendMessage</code> finished and the user will be confused that the received a confirmation for a message ID he had no clue about. Yes, I have methods which can check if a message was sent or not, and yes, I can create a thread which from time to time pulls the <code>MessageStore</code> to see if the message was delivered or not. But I am more specifically interested if it is possible to somehow chain in the two function calls, in case of success: <code>confirmation</code> called right after <code>sendMessage</code> returns. If yes, how? (Please note, I cannot modify the signature of the functions, third party library :( )</p>