Overloading operator for vector class

Hi, I'm working on a dictionary where the user inputs a word and the program looks up it's definition.
I'm using a vector to store each Word class.
I cannot get the code to return it's definition however, as I need to overload the operator "==".

Main:

cout << "Enter a word.";
cin >> wordName;
int vecNum =0;
int vecMax = wordVector.size();

while (vecNum <= vecMax) {
if (wordName == wordVector[vecNum].getWord) {
cout << wordVector[vecNum].getDef;
}
else {
cout << "Word does not exist.";
}
}


Word header:

#ifndef WORD_H
#define WORD_H

#include <string>
using namespace std;

class Word {
public:
Word();
Word(string wordName, string def, string type); //constructor needs all this?
void setWord(string wordName, string def, string type);
string getWord();
string getDef();
string getType();
virtual bool isNoun();

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

private:
string wordName, def, type;
};

bool operator== (const Word &w1, const Word &w2)
{
return w1.wordName == w2.wordName;
}
#endif


Errors:
C2679 binary'==': no operator found which takes a right-hand operand of type 'overloaded-function'
C3867 'Word::getWord' non-standard syntax; use '&' to create a pointer to member
C3867 'Word::getDef'

Sorry if the post comes out weird. First time using the forum and it's bugging out on me.
I think your overload is fine.

The problem is in your comparison - you're missing the parenthesis from getWord().
Oh missed that.
I still have errors though.

LNK1169 one or more multiply defined symbols found
LNK2005 "bool __cdecl operator==(class Word const &,class Word const &)" (??8@YA_NABVWord@@0@Z) already defined in mySearch.obj

Where FileTasker is just a namespace for other functions and mySearch is the current main function.
Last edited on
Topic archived. No new replies allowed.