Hello, everyone.
I was wondering is it possible to override the addition operator so that it will take two constants of type char*.
I tried writing the following code but it only gave me an error message stating "'operator +' must have at least one formal parameter of class type".
Code:
char* operator+(const char* left, const char* right)
{
char* c, *d;
d = new char[strlen(left) + 1];
strcpy(d, left);
c = new char[strlen(left) + strlen(right) + 1];
c = strcat(d, right);
return c;
}
So, is it fundamentally impossible to override this operator outside a user defined class, or is there a way to do it?
If so, how?
Thanks.