I have some code:
const string MY_STRINGS[3] = { "A", "B", "C" };
and when I try to do this:
int main() {
MY_STRINGS[1] = MY_STRINGS[2];
}
I get the following error:
Passing 'const std::string' as 'this' argument of 'std::basic_string... & std::basic_string::operator= ...' discards qualifiers.
Sure. Makes sense. I can't assign to a const string
.
But when I do the following:
int main() {
const string SOME_STRINGS[3] = MY_STRINGS;
MY_STRINGS[1] = MY_STRINGS[2];
}
this compiles and works. What has changed, and why does it now compile?
SOME_STRINGS
toSOME_STRINGS[3] = { MY_STRINGS[0], ... };
. What compiler are you using? Can you post a single block of code that causes this? – hmjdSOME_STRINGS
at all: just stating that I had to use initializer braces for VS2010 to compile it. Anyway, it is not really relevant to your actual question (I was concerned it was not the actual code posted but it has been reproduced). – hmjd