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

Mathieu Lacage mathieu.lacage at sophia.inria.fr
Tue May 13 11:05:52 PDT 2008


On Tue, 2008-05-13 at 17:46 +0100, 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?

+1: avoids many implicit conversion traps.

Mathieu



More information about the Ns-developers mailing list