error: cannot take the address of an rvalue of type 'void'. Two classes with same workflow but one throws error

error: cannot take the address of an rvalue of type 'void'. Two classes with same workflow but one throws error

我有两个工作流程相似的函数。一个是来自 NS3 的修改示例,另一个是生产者节点修改的自旋。

我的制作人

void
ProactiveProducer::SendData(Name dataName)
{
  // dataName.append(m_postfix);
  // dataName.appendVersion();
  if (!m_active)
    return;

  NS_LOG_FUNCTION_NOARGS();

  auto data = make_shared<Data>();
  data->setName(dataName);
  data->setFreshnessPeriod(::ndn::time::milliseconds(m_freshness.GetMilliSeconds()));

  data->setContent(make_shared< ::ndn::Buffer>(m_virtualPayloadSize));

  Signature signature;
  SignatureInfo signatureInfo(static_cast< ::ndn::tlv::SignatureTypeValue>(255));

  if (m_keyLocator.size() > 0) {
    signatureInfo.setKeyLocator(m_keyLocator);
  }

  signature.setInfo(signatureInfo);
  signature.setValue(::ndn::makeNonNegativeIntegerBlock(::ndn::tlv::SignatureValue, m_signature));

  data->setSignature(signature);

  NS_LOG_INFO("node(" << GetNode()->GetId() << ") responding with Data: " << data->getName());

  // to create real wire encoding
  data->wireEncode();

  m_transmittedDatas(data, this, m_face);
  m_appLink->onReceiveData(*data); 

  ScheduleNextPacket();
}

void
ProactiveProducer::ScheduleNextPacket()
{
  NS_LOG_DEBUG ("m_sendEvent: " << m_sendEvent.IsRunning());
  if (m_firstTime) {
    m_sendEvent = Simulator::Schedule(Seconds(0.0), &ProactiveProducer::SendData(m_prefix), this);
    m_firstTime = false;
  } else if (!m_sendEvent.IsRunning()) {
    m_sendEvent = Simulator::Schedule(Seconds(1.0 / m_frequency), &ProactiveProducer::SendData(m_prefix), this);
  }
}

NS3 消费者

void
ModConsumer::SendPacket()
{
  // if the application isn't running don't do anything
  if (!m_active)
    return;

  NS_LOG_FUNCTION_NOARGS();

  // Will be an invalid packet
  uint32_t seq = std::numeric_limits<uint32_t>::max(); // invalid

  /*
    if the integer is positice the loop runs infinitely --> poor code
    - when the size of the list goes to 0 it will exit and therefore seq will be max int
    - the consumer seems to work based off of packets to be retransmitted.
    - removes the first entry in list of packets to be retransmitted
    - removes packet from list of retransmissions
    - then transmits that?
  */
  while (m_retxSeqs.size()) {
    seq = *m_retxSeqs.begin();
    m_retxSeqs.erase(m_retxSeqs.begin());
    break;
  }

  // will check fail conditions or increment sequence
  if (seq == std::numeric_limits<uint32_t>::max()) {
    // NS_LOG_DEBUG ("Reached max Sequence: " << seq << " max_seq: " << m_seq);
    if (m_seqMax != std::numeric_limits<uint32_t>::max()) {
      if (m_seq >= m_seqMax) {
        NS_LOG_DEBUG ("maximum sequence number has been requested, m_seq: " << m_seq << " m_seqMax: " << m_seqMax);
        return; // we are totally done
      }
    }

    seq = m_seq++;
  }

  shared_ptr<Name> nameWithSequence = make_shared<Name>(m_interestName);
  nameWithSequence->appendSequenceNumber(seq);

  shared_ptr<Interest> interest = make_shared<Interest>();
  interest->setNonce(m_rand->GetValue(0, std::numeric_limits<uint32_t>::max()));
  interest->setName(*nameWithSequence);
  interest->setCanBePrefix(false);
  time::milliseconds interestLifeTime(m_interestLifeTime.GetMilliSeconds());
  interest->setInterestLifetime(interestLifeTime);
  interest->setMustBeFresh(true);

  // NS_LOG_DEBUG ("Requesting Interest: \n" << *interest);
  // NS_LOG_INFO("> Interest for " << seq);

  WillSendOutInterest(seq);

  m_transmittedInterests(interest, this, m_face);
  m_appLink->onReceiveInterest(*interest);

  ScheduleNextPacket();
}

// Yes this is a different class, pasting for convenience
void
ModConsumerCbr::ScheduleNextPacket()
{
  NS_LOG_DEBUG ("m_sendEvent: " << m_sendEvent.IsRunning());
  if (m_firstTime) {
    m_sendEvent = Simulator::Schedule(Seconds(0.0), &ModConsumer::SendPacket, this);
    m_firstTime = false;
  } else if (!m_sendEvent.IsRunning()) {
    m_sendEvent = Simulator::Schedule(Seconds(1.0 / m_frequency), &ModConsumer::SendPacket, this);
  }
}

当我 运行 代码时,编译器为生产者抛出以下错误 class

error: cannot take the address of an rvalue of type 'void'
    m_sendEvent = Simulator::Schedule(Seconds(0.0), &ProactiveProducer::SendData(m_prefix), this);

我想我明白为什么会抛出错误。我正在传递一个 void 类型的函数。它不应该是可寻址的。所以我无法理解消费者如何正确编译和运行。任何关于我所缺少的东西的建议将不胜感激。我是 C++ 新手。

更改此行

m_sendEvent = Simulator::Schedule(Seconds(0.0), &ProactiveProducer::SendData(m_prefix), this);

到这个

m_sendEvent = Simulator::Schedule(Seconds(0.0), &ProactiveProducer::SendData, this, m_prefix);

参考:https://www.nsnam.org/doxygen/classns3_1_1_simulator.html#aec5dd434c42edd6c38ef249d2960c321

错误信息

error: cannot take the address of an rvalue of type 'void'

够清楚了

在此声明中

m_sendEvent = Simulator::Schedule(Seconds(0.0), &ProactiveProducer::SendData(m_prefix), this);

第二个参数是一个函数调用表达式,类型为 void - 函数 SendData 的 return 类型。因此,完全不清楚您要获取 void 类型的不完整对象的 ab 地址,而且它是一个右值。

与您在此声明中的代码相反

m_sendEvent = Simulator::Schedule(Seconds(0.0), &ModConsumer::SendPacket, this);

取了一个成员函数的地址。所以这些调用在语义上是不同的。