The homework #3 assignment as handed out in class had 2 problems with it. While I have update the online document to be correct, I will address each problem here for further clarification.
Problem #1:
error C2679: binary '!=' : no operator defined which takes a right-hand
operand of type 'class MGString' (or there is no acceptable conversion)
Details: This problem occurs because the operator!= function, and all other operator functions, where specified as accepting a char* parameter, but the test program uses an MGString object. There is no acceptable conversion from MGString to const char* to satisfy the needs of the compiler.
This problem occured because I had cut back some of the requirements from your homework assignment from a working program. Specifically, I did not ask you to write a conversion operator function. In my solution, I had a conversion operator but I did not pay attention to the fact that it was being used by the test program I distributed. While there are several ways to fix it, I would suggest the following method:
Add the following conversion operator function to your class definition (in the .h file) as a member function:
operator const char* () const { return( GetCPointer() ); }
That is the entire function. Now, anywhere you provide an MGString object where a char* is needed, the conversion operator function above will be called, which will call the GetCPointer function and return a C-style string pointer.
Problem #2
At runtime, program outputs "The '>' operator didn't work".
Details: A simple typo on my part. The original code was:
if( A > B ) cout << "The '>' operator looks Ok" << endl; else cout << "The '>' operator didn't work" << endl;
But, it should have been:
if( A > B ) cout << "The '>' operator didn't work" << endl; else cout << "The '>' operator looks Ok" << endl;