Hi all,
I come across a question that
whether 'const' keyword is applied to object abstract state or bitwise state.
The answer was that const should be applied to object abstract state.
But, const keyword ensures that object bitwise state is not changed.
I am confused over here. Especially with this example.
class MyString
{
char *m_sz;
public:
MyString( const char *s )
{
m_sz = strdup( s );
}
void toUpper() const
{
char *sz = m_sz;
while( (*sz) != '\0' )
{
(*sz) -= 32;
sz++;
}
}
void Print() const
{
printf( "%s\n", m_sz );
}
};
int main(int argc, char* argv[])
{
const MyString myStr( "hello world" );
myStr.toUpper();
myStr.Print();
return 0;
}
Regards.
