尽管命名空间正确,但重复出现错误
Repeated errors despite correct namespace
我在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(。希望它能起作用。再见
相关文章:
- 使用命名空间时出现多个定义错误
- 使用 make 编译 MPI,几个命名空间错误,例如"错误:未知类型名称'使用'?
- 我该怎么做才能摆脱使用命名空间时的语法错误?
- C++ Visual Studio 错误:名称后跟'::'必须是类或命名空间名称 (DirectX 11)
- 在 C++ 中使用命名空间时出现"does not name a type"错误
- C++命名空间中调用 void 函数的错误
- 无法获取 wig %ignore 以忽略命名空间中的类,从而导致编译错误
- 为什么 Clang 在命名空间'std'中没有名为 'copy' 的成员给出错误
- 名称后跟"::"必须是类或命名空间错误,即使"::"后面是类名
- Catalina C++:使用<cmath>标头产生错误:全局命名空间中没有名为 'signbit' 的成员
- Visual C:命名空间范围错误或晦涩功能?
- 共享库中使用"使用命名空间"定义的符号错误
- 如何解决 comiler 错误:'v_bias'不是命名空间名称
- fstream.h 中的 STL 命名空间错误与 qmake/make.
- C++ ,错误:命名空间'std'中的'shared_ptr'未命名模板类型
- 错误:命名空间"std"中没有名为"invoke_result_t"的类型 GCC-7
- 错误:命名空间“PQXX”中的“行”未命名类型
- Xcode 标头错误 - 命名空间'_STL'未包含命名空间'_Rep'
- 错误:命名空间' boost::asio '中的' signal_set '没有命名类型
- 错误:命名空间' std '中的' chrono '没有命名类型