C++ deprecated conversion from string constant to 'char*'

I think that your warnings are coming from this code:

void message(char* m1,
     char* m2="", char*  m3="", char* m4="");

The issue is that string literals in C++ can be treated as char*s, but it's very unsafe to do so. Writing to an array defined by a string literal results in Undefined Behavior (the sort of thing that causes security holes, program crashes, etc.), but a regular ol' char* pointer would allow you to do this sort of write. For this reason, it is strongly suggested that you make all char*s that would point to a C-style string instead be const char*s so that the compiler can check to make sure that you aren't try to write to them. In this case, your code would be better written as

void message(char* m1,
     const char* m2="", const char*  m3="", const char* m4="");

However, since you're using C++, a much better idea is just to use std::string:

void message(std::string m1,
     std::string m2="", std::string m3="", std::string m4="");

This completely avoids the issue, because the C++ std::string type correctly has const char*s in its arguments and makes a deep-copy of the string, so if you try to mutate the string it's guaranteed that you're not going to be trashing the original array of characters.

Hope this helps!

You have a few options:

  • Fix your code so that string literals (eg. "foo") never get implicitly converted to char*. They should be const char*.

  • Change your compiler command line to include -Wno-write-strings. This is what the -Wwrite-strings part of the error message is hinting at.

I would prefer the first option.