gpt4 book ai didi

c++ - 尽管 namespace 正确,但重复出现错误

转载 作者:行者123 更新时间:2023-12-02 11:13:19 25 4
gpt4 key购买 nike

我在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。由于错误属于“未在范围内声明”,因此我不确定如何更正该错误。

这是我对helper类的实现(正在使用):
#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的应用程序文件夹中定义,该文件夹通过 applications-module.h include包含在其中。 在我的代码中,我已在使用RandomAppHelper的位置将其包括在内。

最佳答案

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

关于c++ - 尽管 namespace 正确,但重复出现错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38783459/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com