尽管命名空间正确,但重复出现错误

Repeated errors despite correct namespace

本文关键字:错误 命名空间      更新时间:2023-10-16

我在ns3中添加了一个类,当使用它时,我不断收到错误:

../scratch/seven.cc: In function ‘int main(int, char**)’:
../scratch/seven.cc:102:3: error: ‘RandomAppHelper’ was not declared in this scope
   RandomAppHelper source = RandomAppHelper ("ns3::TcpSocketFactory", InetSocketAddress (Ipv4Address ("192.168.1.10"), 10));
   ^
../scratch/seven.cc:103:3: error: ‘source’ was not declared in this scope
   source.SetAttribute ("Delay", StringValue ("Constant:2.5"));
   ^

代码如下:https://www.nsnam.org/docs/release/3.3/doxygen/application.html

我无法解决这个错误。我在代码中使用了正确的namespace ns3。由于这个错误是"未在范围内声明",我不知道如何纠正它

以下是我的助手类的实现(我正在使用(:

#include "ns3/log.h"
#include "ns3/address.h"
#include "ns3/node.h"
#include "ns3/nstime.h"
#include "ns3/socket.h"
#include "ns3/simulator.h"
#include "ns3/socket-factory.h"
#include "ns3/packet.h"
#include "ns3/uinteger.h"
#include "ns3/trace-source-accessor.h"
#include "ns3/tcp-socket-factory.h"
#include "random-helper.h"
namespace ns3{
RandomAppHelper::RandomAppHelper (std::string protocol, Address remote)
{
  m_factory.SetTypeId ("ns3::MpTcpBulkSendApplication");
  m_factory.Set ("Protocol", StringValue (protocol));
  m_factory.Set ("Remote", AddressValue (remote));
}
void
RandomAppHelper::SetAttribute (std::string name, const AttributeValue &value)
{
  m_factory.Set (name, value);
}
ApplicationContainer
RandomAppHelper::Install (Ptr<Node> node) const
{
  return ApplicationContainer (InstallPriv (node));
}
ApplicationContainer
RandomAppHelper::Install (std::string nodeName) const
{
  Ptr<Node> node = Names::Find<Node> (nodeName);
  return ApplicationContainer (InstallPriv (node));
}
ApplicationContainer
RandomAppHelper::Install (NodeContainer c) const
{
  ApplicationContainer apps;
  for (NodeContainer::Iterator i = c.Begin (); i != c.End (); ++i)
    {
      apps.Add (InstallPriv (*i));
    }
  return apps;
}
Ptr<Application>
RandomAppHelper::InstallPriv (Ptr<Node> node) const
{
  Ptr<Application> app = m_factory.Create<Application> ();
  node->AddApplication (app);
  return app;
}

}

这个类在ns3的应用程序文件夹中定义,该文件夹通过应用程序模块.h include包含在我的代码中,我在使用RandomAppHelper的地方包含了它。

我猜您忘记在应用程序文件夹中的wscript.py文件中添加文件名(我猜您创建了RandomAppHelper(。希望它能起作用。再见