I'm struggling with a warning that cppcheck
(version 1.85 on a Linux machine) is reporting:
someFile.h:23:29: warning: Redundant code: Found a statement that begins with string constant. [constStatement]
const std::string OffOn[]= {"off", "on"};
^
I did some research and found that changing the statement to
const std::string OffOn[]= {std::string("off"), std::string("on")};
removes the warning. However I do not understand what's going on, and what's "bad" about my first solution. Maybe someone can explain it to me? Or give me some hints!
It recommends you use initialization with a braced-init-list
like: const std::string OffOn[]{"off", "on"};
, so =
is just unnecessary.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With