Skip to content

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

Description

@CodingHare

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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions