View Single Post
Mar5-12, 09:32 PM
HW Helper
P: 7,171
Quote Quote by testme View Post
I get what you did, though my teacher said something about you can shorten it to just isEqual under a certain circumstance, am I misusing that and do you know when it can be done?
The first issue is if(...) is the same as if(0 != ...), so you had the sense of the if reversed in your original code. I'm not sure when you can just use isEqual. One issue with C++ is that you can have multiple functions with the same name isEqual, where the only diference is the parameters, for example:

bool isEqual(char *, char *, int); // compare two arrays of characters
bool isEqual(int *, int *, int); // compare two arrays of integers
bool isEqual(double *, double *, int); // compare two arrays of doubles
bool isEqual(char *, char*); // compare two strings terminated by zero
bool isEqual() // always return true if no parameters

"isEqual" by itself means the address of a function. Normally only used when assigning a pointer to function. Although you can overload functions, I don't think you can overload pointer to functions, so the pointer type determines which function to point to:

bool ((*pointertofunctionarrayofchar)(char *, char *, int) = isEqual;
bool ((*pointertofunctionarrayofdouble)(double *, double *, int) = isEqual;