[Ns-developers] Ipv4Address and Ipv4Mask, getting rid of "implicit" constructors

Tom Henderson tomh at tomh.org
Tue May 13 22:55:12 PDT 2008


Gustavo Carneiro wrote:
> Right now you can pass "1.2.3.4"  to a function expecting Ipv4Address or
> Ipv4Mask, and since the constructors do not have an 'explicit' keyword C++
> will call the constructor automatically for us.  This "feature" is used in
> ns-3 src/routing/global-routing-manager, and extensively in examples.
> However I always find it confusing, and it can accidentally disable some
> useful type checking normally done by C++.
> 
> I would like to make all these constructors "explicit", thus you have to
> type Ipv4Address ("1.2.3.4") instead of "1.2.3.4".
> 
> Comments?
> 

Do you mean even the helper APIs?

Currently, the examples read, e.g.

   Ipv4AddressHelper ipAddrs;
   ipAddrs.SetBase ("192.168.0.0", "255.255.255.0");

are you suggesting:

   Ipv4AddressHelper ipAddrs;
   ipAddrs.SetBase (Ipv4Address ("192.168.0.0"), Ipv4Mask 
("255.255.255.0"));

if so, could we support the string-based API explicitly via overloaded 
helper functions and avoid the extra typing here?  It just seems 
needlessly verbose to me.

Tom




More information about the Ns-developers mailing list