PacktPublishing / The-Modern-Cpp-Challenge

The Modern C++ Challenge, published by Packt
MIT License
308 stars 105 forks source link

Chapter 2/ Problem 16 #6

Open MikeLupanov opened 3 years ago

MikeLupanov commented 3 years ago

the postfix operator++ does not work correctly, because it returns **this* instead result**:

    ipv4& operator++(int)  // need return by value ipv4 opetrator++(int)
    {
        ipv4 result(*this);
        ++(*this);
        return *this; // need result
    }
mariusbancila commented 3 years ago

Thank you for pointing this error. It has been reported by other readers and should have been added to the errata, although I don't know exactly where that is located.

The postfix operator++ is wrong in the book. It's correct implementation is this:

ipv4 operator++(int)
{
   ipv4 result(*this);
   ++(*this);
   return result;
}