May 2018
Intermediate to advanced
328 pages
8h 15m
English
To be able to enumerate IPv4 addresses in a given range, it should first be possible to compare IPv4 values. Therefore, we should implement at least operator<, but the following listing contains implementation for all comparison operators: ==, !=, <, >, <=, and >=. Also, in order to increment an IPv4 value, implementations for both the prefix and postfix operator++ are provided. The following code is an extension of the IPv4 class from the previous problem:
ipv4& operator++(){ *this = ipv4(1 + to_ulong()); return *this;}ipv4& operator++(int){ ipv4 result(*this); ++(*this); return *this;}friend bool operator==(ipv4 const & a1, ipv4 const & a2) noexcept{ return a1.data == a2.data;}friend bool operator!=(ipv4 ...Read now
Unlock full access