|
-
April 28th, 2004, 06:19 PM
#1
Overloaded operators calling each other.
Hello peoples.
I'm just learning about C++ classes, and overloading operators. I'm having some trouble with two overloads, one of which is operator==(char * ), and the other one is operator==(const CStr&).
Both of these methods contain the exact same code, with the only difference is that one takes a pointer to a character array, while the other one takes a class instance. I would like to be able to call the operator== that takes the character array from within the class instance method, to cut down on code.
Class Calls (Both of which are public):
int operator==( char *);
int operator==(const CStr&);
Method for == "String", same code for Class instance:
int CStr::operator ==(char * pIncomingString)
{
int Match = 1;
int Counter = 0;
while (Counter < Next && Match != 0)
{
if (*(pIncomingString + Counter) == Text[Counter++])
Match = 1;
else
Match = 0;
}
return Match;
}
From within the method with the class instance, I have tried a variety of lines to try to call this, but so far either it doesn't work at all, or it errors out.
operator==(IncomingClass.Text);
I have been working with this line, but no luck. I've tried to do Text==(IncomingClass.Text). This line will compile fine, but does not give me the expected results.
This code is for a project, which is complete, but am curious why I cannot call correctly another method and reduce duplicate code.
Thanks
-Jeff
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|