Exercise information
Exercise 7.53: Define your own version of Debug.
Question or Bug
If you're using C++ 14(or higher) to compile the answer, the any() function, which is defined as:
constexpr bool any() {return hw || io || other; } (line 16)
must be written in:
constexpr bool any() const {return hw || io || other; }
in order to claim itself a const member function. Otherwise the compiler will complain:
error: passing ‘const Debug’ as ‘this’ argument discards qualifiers [-fpermissive]
i hope this helps!
Ref: Difference between constexpr and const
See the B section in the first answer.
Enviroment information
- System: :centos 7.2
- Compiler version/IDE: : g++ 11 & g++ 14
Exercise information
Exercise 7.53: Define your own version of Debug.
Question or Bug
If you're using C++ 14(or higher) to compile the answer, the any() function, which is defined as:
constexpr bool any() {return hw || io || other; }(line 16)must be written in:
constexpr bool any() const {return hw || io || other; }in order to claim itself a const member function. Otherwise the compiler will complain:
error: passing ‘const Debug’ as ‘this’ argument discards qualifiers [-fpermissive]i hope this helps!
Ref: Difference between
constexprandconstSee the B section in the first answer.
Enviroment information