struct a {
string c;
a(string x) {
c = x;
}
};
int main()
{
map <int, a*> m;
m[1] = &a("hej");
cout << m[1]->c;
}
Outputs nothing. However, if I change the parameter in "struct a" to take a int instead of a string it outputs the int. So why nothing if it's a string?
Old versions of MSVC and GCC used to only issue a warning diagnostic for taking the address of a temporary, but any even somewhat-recent compiler should error out... I suggest updating your compiler. But even on an outdated compiler, it should at least be a warning, so ALWAYS compile with at least -Wall on GCC, and turn on extra/pedantic too for good measure.
@Ganado, I'd add to your suggestions....when using MSVC set the warning level to 4. Anything higher and you get gobs of unnecessary and useless warnings about the C++ standard library.