Is this possible? i get weird error message when i put char as the type:
inline bool operator==(const char *str1, const char *str2){
// ...
}
Error message: error C2803: 'operator ==' must have at least one formal parameter of class type … which i dont understand at all.
I was thinking if i could directly compare stuff like:
const char *str1 = "something";
const char *str2 = "something else";
const char str3[] = "lol"; // not sure if this is same as above
and then compare:
if(str1 == str2){
// ...
}
etc.
But i also want it to work with:
char *str = new char[100];
and:
char *str = (char *)malloc(100);
I am assuming every char array i use this way would end in NULL character, so the checking should be possible, but i understand it can be unsafe etc. I just want to know if this is possible to do, and how.
It is not possible. As your compiler points out, you cannot overload this operator for primitive data types. At least one side of the comparison must be non-primitive for the overload to be possible.
In the same sense, you cannot derive a new class from a primitive data type (to add functionality to it).