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 :
An array of structures in C
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 ?
Confused is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.