Just stumbled on to this problem/fix while writing some C++ code for my CS courses…
warning: deprecated conversion from string constant to ‘char*’
I hadn’t really thought about this much, as previous versions of g++ (such as the 3.4.3 version we’re using on our university systems) never complained about this issue, but g++ 4.2.3 does. The fix, as I found from multiple posts around the web, is to change all function arguments that will be expected to take a string constant from “char *” to “const char *”. For example:
Function Call:
class.someFunction("");
Original Function Prototype:
void class::someFunction(char *);
Updated Function Prototype:
void class::someFunction(const char *);
I’m somewhat new to C++ (OSU taught Java and I code in C# for the day job), so please give me a bit of slack on this one if you’re a seasoned pro.
As always, comments and questions are welcome via my comment box. Thanks for reading!





May 10, 2008 at 2:09 am
I’ve run into the same thing and it’s giving me hearburn. I’ve always believed that there’s no such thing as deprecation in C++. To me “deprecation” is abandonment of backwards compatibility. I’ve been trying to find out if the standards committee actually approves of deprecation or whether these error messages are simply misleading.
May 14, 2008 at 9:52 am
Call the function by casting the parameter to
“char *” type. Instead of function call
class.someFunction(”");
use
class.someFunction((char *)”");
That should fix your warning problem