c++ - Operator(s) too many parameters for this function? -


made own string class (i.e. homework obviously) , getting odd syntax errors on 2 of operators. equality , add operators claim have many parameters (i.e. in .h file), claim method not belong class in .cpp file!

i made equality operator friend, intellisense still gives me same error messages.

does know 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 length of left , right hand sides of add operator     int lengthlhs = strlen(lhs.mstr);     int lengthrhs = strlen(rhs.mstr);      //allocate space left , right hand sides (i.e. plus null)     char * buffer = new char[lhs.mstr + rhs.mstr + 1];      //copy left hand side buffer     strcpy(buffer, lhs.mstr);      //concatenate right hand side buffer     strcat(buffer, rhs.mstr);      //create new string     string newstring(buffer);      //delete buffer     delete [] buffer;      return newstring; } 

you need define operator== outside class:

bool string::operator==(string const & left, string const &right)      ^^^^^^^^ remove 

if operator+ friend, needs defined free function (i.e. outside class).


Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -