Re: about stl map class
* blackbiscuit:
On 5?19?, ??1?00?, Neelesh <neelesh.bo...@gmail.com> wrote:
Whether all string literals are distinct or not is implementation
dependent. Which effectively means that
int main()
{
const char* p = "June";
const char* q = "June";
bool eq = p == q;
}
Whether "eq" is true or false is implementation dependent. so in the
current case whether map[p] will be same as map["June"] is
implementation dependent. Not just that, even the output of following
* blackbiscuit:
code is implementation dependent
#include <map>
#include <iostream>
int main()
{
std::map<const char*, int> m;
m["June"] = 5;
std::cout << m["June"] << std::endl; //Is the string literal
"June" on this line same as string literal "June" on the previous
line? Implementation dependent.
}
So it means to use map in that way is quite dangerous. Is there any
general way to avoid that problem?
Use e.g. std::string as key.
Cheers & hth.,
- Alf
--
Due to hosting requirements I need visits to <url: http://alfps.izfree.com/>.
No ads, and there is some C++ stuff! :-) Just going there is good. Linking
to it is even better! Thanks in advance!