Usually I have something like:
class simpledata { public: simpledata(int v1, int v2) : m_v1(v1), m_v2(v2) { } const int m_v1, m_v2 ; } ;
This way I can let others see m_v1 & m_v2 and not worry about the values getting modified. Unfortunately it doesn't work with char[].
class simplestringdata { public: simplestringdata(int v1, char * s1) : m_v1(v1) { strcpy(m_s1, s1) ; // XX - not allowed } const int m_v1 ; const char * const m_s1[MAXSIZE] ; } ;
My solution is let const members be modified in the constructor. It seems the right thing to do, after all you can do it in the initialization list, why not the constructor. Maybe special case it to only allow it for const int members at the same level, ie you can't modify const members of your parent. (Or maybe you could ...)
And no, the answer is not to use the 'string' class.
No comments:
Post a Comment