我试图在我的 c++ 模拟中实现数组(提供的这种编码是在一个网络数据包字段中有 2 个值)
这是我的变量声明(在标题中)
Ptr<Name> m_names [2];
这是我的函数声明(在标题中)
void SetName (unsigned which, Ptr<Name> name);
void SetName (unsigned which, const Name &name);
在源文件中
void Interest::SetName (unsigned which, Ptr<Name> name)
{
if (which < 2)
{
m_names[which] = name;
}
}
void Interest::SetName (unsigned which, const Name &name)
{
if (which < 2)
{
m_names[which] = Create<Name> (name);
}
}
我这样称呼的方式是这样的(在我的主文件中):
interest->SetName (0, nameWithSequence);
interest->SetName (1, nameWithNextSequence);
结果它给出了这样的错误
src/ndnSIM/bindings/ns3module.cc: In function ‘PyObject* _wrap_PyNs3NdnData_SetName__0(PyNs3NdnData*, PyObject*, PyObject*, PyObject**)’:
src/ndnSIM/bindings/ns3module.cc:8418:62: error: no matching function for call to ‘ns3::ndn::Data::SetName(ns3::Ptr<ns3::ndn::Name>)’
src/ndnSIM/bindings/ns3module.cc:8418:62: note: candidates are:
./ns3/ndn-data.h:60:3: note: void ns3::ndn::Data::SetName(unsigned int, ns3::Ptr<ns3::ndn::Name>)
./ns3/ndn-data.h:60:3: note: candidate expects 2 arguments, 1 provided
问题是我应该声明正确的陈述的正确方法是什么。感谢任何形式的帮助
编辑我找到了一些 pyhton 定义来绑定我的 c++ 代码(SetName)
def __setattr__(self, name, value):
if name == "_interest":
return object.__setattr__ (self, name, value)
elif name == "name":
if value is None:
return self._interest.SetName (ns.ndnSIM.ndn.Name ())
elif isinstance (value, Name):
return self._interest.SetName (value._name)
elif isinstance (value, ns.ndnSIM.ndn.Name):
return self._interest.SetName (value)
elif isinstance (value, str):
return self._interest.SetName (ns.ndnSIM.ndn.Name (value))
else:
raise ValueError ("Invalid name parameter")
如何以及解决此问题的正确方法是什么。谢谢