The following code, written years ago in C, will not compile in the Community version of Microsoft Visual Studio for C++:
typedef struct {
char* szString;
int iID;
} LocalStringElement;
LocalStringElement l_sTheStrings[] = {
{"Simple", 0}, {"S", 0},
{"Triangular", 1}, {"T", 1},
{"Weighted", 2}, {"W", 2},
{"Exponential", 3}, {"E", 3}
};
Later on in the code it uses l_sTheStrings[some value].szString and l_sTheStrings[some value].iID, so it looks to be putting structures as elements of an array.
Using the C++ debugger gives, as an example,the following type of error message :
error C2440: 'initializing': cannot convert from 'const char [7]' to 'char *'
Conversion from string literal loses const qualifier (see /Zc:strictStrings)
Looking at other answers, such as :
it looks like maybe swap char* szString to be const char* szString, but I was not sure if this is a sound thing to do and gives exactly the same behaviour as the C coding intended ?
const char*instead.char*pointer to point to literal string. That's because literal strings are constant in C++ (unlike C), so you must useconst char*. Either that, or makeszStringan array, or usestd::stringif you really want to go C++.