class MyString {
private:
char *m_pchString;
int m_nLength;
public:
MyString(char* pchString="0") { //problem on this parameter
m_nLength = strlen(pchString)+1;
m_pchString = new char[m_nLength];
strncpy(m_pchString, pchString, m_nLength);
m_pchString[m_nLength-1] = 0;
}
~MyString() {
delete[] m_pchString;
m_pchString = 0;
}
char* GetString() {return m_pchString;}
int GetLength() {return m_nLength;}
};
If I complied this, the compiler will send me a warning:
warning: deprecated conversion from string constant to 'char*'
unless I modify the parameter from char *pchString = "0"
to const char *pchString = "0"
Why is the default char* in a parameter must be const?