문제

Topology helper Ipv4AddressHelper allows to set the base address as shown in the example.

Ipv4AddressHelper address;
address.SetBase ("10.1.1.0", "255.255.255.0");

I want store an arbitrary number of addresses dynamically created, for example.

  ...
  for( uint32_t subnetC = 0; subnetC < nSubnets; subnetC++ )
  {    
     string ip = "10.1." + lexical_cast< string >( subnetC + 1 ) +".0";
     ipList.push_back( ip );
  }
  ...
  vIpv4AddressHelper[ someIndex ].SetBase(ipList[ someIndex ], "255.255.255.0" );
  ...

However, I get the error

 error: no matching function for call to ‘ns3::Ipv4AddressHelper::SetBase(std::basic_string<char, std::char_traits<char>, std::allocator<char> >&, const char [14])’
 note: candidates are: void ns3::Ipv4AddressHelper::SetBase(ns3::Ipv4Address, ns3::Ipv4Mask, ns3::Ipv4Address)

How do I pass a string to SetBase ?

도움이 되었습니까?

해결책

The compiler tells you that the candidate needs 2 params (the third one is optional. Also, see the doc for Ipv4AdressHelper). So pass those params. In the docs you can see that Ipv4Adress can be constructed with a char const*. So try:

address.SetBase (ns3::Ipv4Adress(adress_string.c_str()), ns3::Ipv4Mask(mask_string.c_str()));

Changing adress_string and mask_string accordingly to your needs.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top