In header (.h) file
class MyClass {
...
const MyClass & operator++(); // prefix form
MyClass operator++(int); // postfix form
...
};
In source (.cpp) file
const MyClass & MyClass::operator++() { // prefix form
// code to increment data members
return *this;
}
MyClass MyClass::operator++(int) { // postfix form
MyClass temp = *this;
// code to increment data members
return temp;
}
Note:
In string library ( #include <string> )
Overloaded support for relational operators ( == != > >= < <= = )
C++ strings are mutable:
Useful member functions:
Recommendation:
C-style string = an array of characters ending in '\0'
Library support in cstring (need to #include <cstring>):
int strlen( const char *str ) char * strcpy( char *LHS, char *RHS ) char * strcat( char *LHS, char *RHS ) int strcmp( const char *LHS, const char *RHS )