Hello, I trying to creator an operator << between an ostream and a SENTENCE_TYPE (an Enum):
//Sentence type
enum class SENTENCE_TYPE {ANSWER, MESSAGE, NONE};
//operator
// define needed operator to conversion
std::ostream& operator<< (std::ostream& os, SENTENCE_TYPE type) {
if (type == SENTENCE_TYPE::ANSWER)
os << 'A';
else if (type == SENTENCE_TYPE::MESSAGE)
os << 'M';
else
os << 'N';
return os;
}
but when I compile it, I have this error:
Severity Code Description Project File Line Suppression State
Error LNK2005 "class std::basic_ostream<char,struct std::char_traits<char> > & __cdecl operator<<(class std::basic_ostream<char,struct std::char_traits<char> > &,enum SENTENCE_TYPE)" (??6@YAAEAV?$basic_ostream@DU?$char_traits@D@std@@@std@@AEAV01@W4SENTENCE_TYPE@@@Z) already defined in DoNotAnswerGameModeBase.cpp.obj DoNotAnswer G:\WORK\EXODIA STUDIO\EXODIA STUDIO\Exodia Video Game\DoNotAnswer\App\DoNotAnswer\Intermediate\ProjectFiles\MSC_SaveSystem.cpp.obj 1
I don’t know how to fix this. thanks in advance.