Operator(s) too many parameters for this function?
c++, operator-overloading
Solution
You need to define `operator==` outside the class:
bool String::operator==(String const & left, String const &right)
^^^^^^^^ REMOVE THIS
If `operator+` is also a friend, it too needs to be defined as a free function (i.e. outside the class).
Problem
Made my own string class (i.e. for homework obviously) and am getting odd syntax errors on two of my operators. My equality and add operators claim I have too many parameters (i.e. in my .h file), but then claim the method does not even belong to the class in my .cpp file! I even made the equality operator a friend, but the intellisense still gives me the same error messages. Does anyone know what I am doing wrong?? ``` friend bool operator==(String const & left, String const & right); ``` string.h ``` bool operator==(String const & left, String const & right); String const operator+(String const & lhs, String const & rhs); ``` string.cpp ``` bool String::operator==(String const & left, String const &right) { return !strcmp(left.mStr, right.mStr); } String const String::operator+(String const & lhs, String const & rhs) { //Find the length of the left and right hand sides of the add operator int lengthLhs = strlen(lhs.mStr); int lengthRhs = strlen(rhs.mStr); //Allocate space for the left and right hand sides (i.e. plus the null) char * buffer = new char[lhs.mStr + rhs.mStr + 1]; //Copy left hand side into buffer strcpy(buffer, lhs.mStr); //Concatenate right hand side into buffer strcat(buffer, rhs.mStr); //Create new string String newString(buffer); //Delete buffer delete [] buffer; return newString; } ```