title: Return a value from lambda function inside a function c++
body: <p>I am working with RabbiMQ (RPC) and I want to return a value from a lambda function. I am calling this function from main.cpp but the return value is not as expected (the value inside the lambda function is as expected). What is the right syntax for this?</p>
  
  <p>My code:</p>
  
  <pre><code>bool RabbitMqHandler::sendResultToUserCountService(analyze_result result, Camera *cam)
  {
      std:: string queueName = "userCountServiceReceiveRPC" + std::to_string(cam-&gt;getUserGroupId());
  
      const std::string correlation("2");
  
      SimplePocoHandler handler("localhost", 5672);
  
      AMQP::Connection connection(&amp;handler, 
                                  AMQP::Login("localhost","123456!"),"/");
  
      bool isExist;
      AMQP::Channel channel(&amp;connection);
      AMQP::QueueCallback callback = [&amp;](const std::string &amp;name,
                                         int msgcount,
                                         int consumercount)
      {
  
           ProtobufLPR::CarResult carResult;
  
           carResult.set_licensenumber(result.LicenseNumber);
           carResult.set_analyzetime(result.Date);
  
           std::string buf;
           carResult.SerializeToString(&amp;buf);
  
           AMQP::Envelope env(buf);
           env.setCorrelationID(correlation);
           env.setReplyTo(name);
           channel.publish("", queueName, env);
           std::cout &lt;&lt; "Requesting " &lt;&lt; result.LicenseNumber &lt;&lt; std::endl;
      };
  
      channel.declareQueue(AMQP::exclusive).onSuccess(callback);
  
      auto receiveCallback = [&amp;](const AMQP::Message &amp;message,
                                 uint64_t deliveryTag,
                                 bool redelivered) -&gt;bool
      {
          if(message.correlationID() != correlation)
              return 1;
  
          std::cout&lt;&lt;"Got " &lt;&lt; message.message() &lt;&lt;std::endl;
          handler.quit();
          istringstream(message.message()) &gt;&gt; isExist;
          return isExist;
        };
  
        channel.consume("", AMQP::noack).onReceived(receiveCallback);
        handler.loop();
  }
  </code></pre>