PacktPublishing / The-Modern-Cpp-Challenge

The Modern C++ Challenge, published by Packt
MIT License
312 stars 106 forks source link

Chapter 02 Problem 15 - Wrong array initialization #9

Open iarede opened 2 years ago

iarede commented 2 years ago

The default constructor initializes only the data[0] element:

https://github.com/PacktPublishing/The-Modern-Cpp-Challenge/blob/a3eb81b153758c90f1de7a82792892814e69839e/Chapter02/problem_15/main.cpp#L10 \ For example, if you change the code as follows:

constexpr ipv4() :data{ {42} } {}

then

ipv4 ip;
std::cout << ip << std::endl;

produces:

42.0.0.0

\ Possible fix:

constexpr ipv4() :data{ {0, 0, 0, 0} } {}
mariusbancila commented 2 years ago

That's correct. Thanks for pointing it out.