jeudi 22 septembre 2016

issue with friend operator overloading c++11

I have 2 classes: Word and Control

in Word.h file, there are some operators overloaded like this:

friend bool operator<(const Word& w1, const string& w2);
...
friend bool operator==(const Word& w1, const string& w2);

it seemed strange for me in the beginning cause I thought a comparison between words should only receive 1 word as a parameter, but it's not what happens.

In Control.cpp file, I've got a method (declared in Control.h and implemented in Control.cpp) that search for a Word using a string (class Word has a string as attribute), and I thought as the Control does that, he should have that "friend bool operator < ..." implemented inside him, but when I do it, the compiler says I'm redefining the method.

How/Where should I write this operators logics?

(files I have: Word.h, Control.h and Control.cpp)

Aucun commentaire:

Enregistrer un commentaire