C++ 重复错误,尽管名称空间正确

C++ 重复错误,尽管名称空间正确,c++,error-handling,compiler-errors,ns-3,C++,Error Handling,Compiler Errors,Ns 3,我在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", InetSocketA

我在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"));
   ^
代码如下:

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

下面是我对helper类的实现(我正在使用它):

#包括“ns3/log.h”
#包括“ns3/address.h”
#包括“ns3/node.h”
#包括“ns3/nstime.h”
#包括“ns3/socket.h”
#包括“ns3/simulator.h”
#包括“ns3/插座工厂.h”
#包括“ns3/packet.h”
#包括“ns3/uinteger.h”
#包括“ns3/trace source accessor.h”
#包括“ns3/tcp套接字工厂.h”
#包括“random helper.h”
名称空间ns3{
RandomAppHelper::RandomAppHelper(std::字符串协议,远程地址)
{
m_factory.SetTypeId(“ns3::MpTcpBulkSendApplication”);
m_factory.Set(“协议”,StringValue(协议));
m_factory.Set(“远程”,地址值(远程));
}
无效的
RandomAppHelper::SetAttribute(标准::字符串名称、常量属性值和值)
{
m_factory.Set(名称、值);
}
应用容器
RandomAppHelper::安装(Ptr节点)常量
{
返回应用程序容器(InstallPriv(node));
}
应用容器
RandomAppHelper::安装(标准::字符串节点名)常量
{
Ptr node=Names::Find(nodeName);
返回应用程序容器(InstallPriv(node));
}
应用容器
RandomAppHelper::安装(NodeContainer c)常量
{
应用程序容器应用程序;
for(NodeContainer::迭代器i=c.Begin();i!=c.End();+i)
{
apps.Add(InstallPriv(*i));
}
返回应用程序;
}
Ptr
RandomAppHelper::InstallPriv(Ptr节点)常量
{
Ptr app=m_factory.Create();
节点->添加应用程序(应用程序);
返回应用程序;
}
}

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

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

这似乎不是一个标准的ns3类,而是一个必须自己定义和实现的助手类。我添加了更多的解释。Porque downvote?@JoachimPileborg当然,我自己定义并实施了它。你在哪里定义的?是否包含定义类的头文件?请尝试创建一个链接,并向我们展示(在问题主体中)。@JoachimPileborg添加了详细信息。抱歉刚才的笨拙。
#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;
}


}