Hey its simple. Just When you are calling the base class implementation with
ofstream::operator<<(ptr);
Actually you are calling the address of the actual string but the old implementation requires no type casting and so it prints the string but the new one prints the address of the ptr into the file.