Free functions in the header file should be marked as inline or modified to have only declarations in the header:
inline bool operator==(const Listening &first,const Listening &other) {
and similarly for operator!= .
The original problem is that any unit, including this header file, will have its own object file containing a copy of operator== . Then the linker sees this and does not know which one should be correct. inline can be seen as a linker directive to say: "All of these functions are the same, just select one." Link to more detailed answers.
The same thing did not happen with member function bodies, because such bodies, written inside the class definition, are implicitly inline .
Historical background: Initially, inline was primarily an optimization directive. However, today's compilers are smart enough to make their own optimization decisions; so the main use of inline now is what used to be a secondary effect: avoid multiple definition errors when there is a function in the header.
By the way, you can write return bla; instead of assigning bla to bool variable, etc.
source share