Dear Sir or Madam:
What I have learned in school is when dealing with character string(char array)
we need to use strcpy() function, but I wonder why doing arithmetic assignment
on char string works fine without error or illegal syntax such as following code:
Code:
class Chat
{
public:
Chat();
void SetMessage(char *msg)
{
m_message = msg; // instead of using strcpy(m_message, msg)
}
char * GetMessage()
{
return m_message;
}
~Chat();
private:
char * m_message;
}
int main()
{
char *message = "Hello there";
Chat FunChat;
FunChat.SetMessage(message);
cout << "Message name: " << FunChat.GetMessage();
return 0;
}
Can any C++ experts out there help to explain why? I think if character string assigment works Ok then I don't have to include the string.h that might causing overhead.
Thank you very much for your help.
DV007