0

I am trying to "=default" my friend functions but keep getting the following error:

a4.cpp:180:17: error: declaration of ‘bool operator==(const playing_card&, const playing_card&) noexcept’ has a different exception specifier

  180 |     friend bool operator==(playing_card const&, playing_card const&) noexcept = default;

      |                 ^~~~~~~~

In file included from a4.cpp:15:

a4-provided.hpp:64:6: note: from previous declaration ‘bool operator==(const playing_card&, const playing_card&)’

   64 | bool operator==(playing_card const&, playing_card const&);

Line 64 is in a header file and is not meant to be changed. Line 180 is intended to be defaulted and is the line of code I am working on (can be changed).

I've tried looking into the function definitions and other instances of this happening but could not find a definitive answer. My guess is that I need to replace 'noexcept' with something else, but I'm not sure what it could be.

mariacat
  • 25
  • 2
  • 3
    The function is declared with `noexcept` in one place and without in the other. That's what the error is telling you. Decide which way you want to go with it, and declare it the same way in both places. – Igor Tandetnik Feb 28 '23 at 03:20
  • 2
    If the version without `noexcept` is the one you cannot change and must adhere to, the correct thing to replace `noexcept` with is "nothing at all". – Nathan Pierson Feb 28 '23 at 03:23
  • Why did you decide to add `noexcept` to the definition? – molbdnilo Feb 28 '23 at 08:53

1 Answers1

1

The problem is that the declarations for your overloaded operator== does not match with each other. In particular, one such declaration uses noexcept while the other does not.

To solve this, make sure the declarations match with each other as well as with the definitions when using noexcept.

Jason
  • 36,170
  • 5
  • 26
  • 60