I have written MyString and MyStringConst class. Now I need from time to time pass MyString as MyStringConst, hence overload cast operator. I have written this
MyString::operator const MyStringConst &() const
{
return reinterpret_cast<const MyStringConst &>(*this);
}
MyString has this data
char * str;
int length;
volatile int hashCode;
int bufferSize;
MyStringConst has this data
const char * c_str;
int length;
volatile int hashCode;
Plus there are some methods, that in both strings can recalculate hashCode.
Is this code correctly written. I have tested it on MSVC 2013 and it is working correctly, but I have no idea if it can be used in production code, that can be compiled with different compiler.