Error while creating array of obejcts in NS-3

174 views
Skip to first unread message

Nikos Bizanis

unread,
Mar 9, 2015, 6:28:58 PM3/9/15
to ns-3-...@googlegroups.com
In an NS-3 .cc file I am trying to create an array of instantiations of the UdpEchoClientHelperclass, just by doing:
UdpEchoClientHelper echoClient[NO_OF_NODES];
and when I am trying to build I am getting the error message:
../scratch/test.cc:55:33: error: no matching function for call to ns3::UdpEchoClientHelper::UdpEchoClientHelper()’
Am I doing something wrong at the array declaration?

Konstantinos

unread,
Mar 9, 2015, 7:05:39 PM3/9/15
to ns-3-...@googlegroups.com
Hi Nikos,

The message is clear. There is no empty constructor defined for UdpEchoClient nor for UdpEchoServer.
For the Client you need to pass an IP and a port number and for the server you need just the port.

The idea of the helper class is to mask the loops and make your life easier. 
If you want to create NO_OF_NODES pairs of Client/Server, then you can create your array of NO_OF_NODES UdpClient applications like this (similarly for Server)

Ptr<UdpClient> *app = new Ptr<UdpClient>[NO_OF_NODES];

for (int i=0; i<NO_OF_NODES ; i++){
   app
[i] = CreateObject<UdpClient>();
   app
[i]->SetAttribute ("RemoteAddress", AddressValue ( ... ));
... //configure the rest of the attributes you want
}

Nikos Bizanis

unread,
Mar 10, 2015, 6:54:34 AM3/10/15
to ns-3-...@googlegroups.com
Hi Konstantinos,

I did what you proposed to declare my array and I am still getting an error message in the line:

Ptr<UdpEchoClientHelper> *echoClient = new Ptr<UdpEchoClientHelper>[NO_OF_NODES];

The error message I am getting is, namely:

./ns3/ptr.h: In instantiation of ‘ns3::Ptr<T>::~Ptr() [with T = ns3::UdpEchoClientHelper]’:
../scratch/test.cc:55:70:   required from here
./ns3/ptr.h:756:7: error: ‘class ns3::UdpEchoClientHelper’ has no member named ‘Unref’


Is anything wrong with that implementation?

Thank you.

Tommaso Pecorella

unread,
Mar 10, 2015, 7:06:17 AM3/10/15
to ns-3-...@googlegroups.com
Hi,

please study the documentation and understand what helpers are for. You do not need to have multiple UdpEchoClientHelper instances. Moreover, UdpEchoClientHelper can not be used as a Ptr template argument.

T.
Reply all
Reply to author
Forward
0 new messages