Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ex.7.53 will not compile under the C++14 standard #206

Open
CodingHare opened this issue Nov 25, 2021 · 0 comments
Open

Ex.7.53 will not compile under the C++14 standard #206

CodingHare opened this issue Nov 25, 2021 · 0 comments

Comments

@CodingHare
Copy link

CodingHare commented Nov 25, 2021

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant