StringValue not declared in this scope

672 views
Skip to first unread message

Xiruo Liu

unread,
Apr 11, 2014, 3:38:23 PM4/11/14
to ns-3-...@googlegroups.com
Hi,

I have a problem about StringValue(). Part of my code is show below:

              Ptr<UniformRandomVariable> t = CreateObject<UniformRandomVariable> ();
              int tunnelIndex = t ->GetInteger (1, nodeNum);
              std::string tmp;
              std::ostringstream convert;
              convert << tunnelIndex;
              tmp = convert.str();
              std::string TunnelIP = "10.1.1." + tmp;
              Ipv4Address fakey = Ipv4Address(StringValue(TunnelIP));

And I got the error : 'StringValue' was not declared in this scope. I included <string> already. Is there anyone can help me with this? Thanks in advance.

Tommaso Pecorella

unread,
Apr 11, 2014, 3:59:08 PM4/11/14
to ns-3-...@googlegroups.com
Hi,

it's defined in "ns3/core-module.h" (or in "ns3/string.h")

T.

Xiruo Liu

unread,
Apr 11, 2014, 4:56:52 PM4/11/14
to ns-3-...@googlegroups.com
Now I include "ns3/core-module.h",  "ns3/string.h" and <string> but still have error below. Any hint?

../src/internet/model/ipv4-l3-protocol.cc: In member function ‘virtual void ns3::Ipv4L3Protocol::Send(ns3::Ptr<ns3::Packet>, ns3::Ipv4Address, ns3::Ipv4Address, uint8_t, ns3::Ptr<ns3::Ipv4Route>)’:
../src/internet/model/ipv4-l3-protocol.cc:697:73: error: no matching function for call to ‘ns3::Ipv4Address::Ipv4Address(ns3::StringValue)’
../src/internet/model/ipv4-l3-protocol.cc:697:73: note: candidates are:
./ns3/ipv4-address.h:55:3: note: ns3::Ipv4Address::Ipv4Address(const char*)
./ns3/ipv4-address.h:55:3: note:   no known conversion for argument 1 from ‘ns3::StringValue’ to ‘const char*’
./ns3/ipv4-address.h:45:12: note: ns3::Ipv4Address::Ipv4Address(uint32_t)
./ns3/ipv4-address.h:45:12: note:   no known conversion for argument 1 from ‘ns3::StringValue’ to ‘uint32_t {aka unsigned int}’
./ns3/ipv4-address.h:40:3: note: ns3::Ipv4Address::Ipv4Address()
./ns3/ipv4-address.h:40:3: note:   candidate expects 0 arguments, 1 provided
./ns3/ipv4-address.h:38:7: note: ns3::Ipv4Address::Ipv4Address(const ns3::Ipv4Address&)
./ns3/ipv4-address.h:38:7: note:   no known conversion for argument 1 from ‘ns3::StringValue’ to ‘const ns3::Ipv4Address&’

Konstantinos

unread,
Apr 11, 2014, 5:04:05 PM4/11/14
to ns-3-...@googlegroups.com
The output you get is clear.

You try to create a Ipv4Address using a non-defined constructor. Basically you pass the wrong type of argument. It just needs a const char*, i.e. Ipv4Address('192.168.0.1') is enough and Ipv4Address(StringValue('192.168.0.1')) is wrong!

Xiruo Liu

unread,
Apr 11, 2014, 5:20:41 PM4/11/14
to ns-3-...@googlegroups.com
Yes, I should convert the string variable to char. Thank you very much.
Reply all
Reply to author
Forward
0 new messages