Hi all C++ programming fellows
Making some experiments with string objects I've seen what I think is a confussing behaviour.
If you want to create an empty string, you have this option (taking from string reference in this web page)
string empty_str (); // No parameters.
Then, if you try this:
cout << ">" << empty_str "<\n"
you get an "1" (the number one)
¿¿???.
If you repeat this but using
string empty_str ("");
everything is as expected.
More, if you try to get the length of this empty string. You get a compiler error in the first case, but OK in the second, (getting length 0)
Compiler error: "strings.cpp: In function ‘int main()’:
strings.cpp:10: error: request for member ‘empty’ in ‘empty_str’, which is of non-class type ‘std::string()’"
Weird, isn't it?. Do some of you have an explanation on this?, Am I an asshole and there is something obvious I haven't seen?
I'm using Linux Ubuntu. g++ gcc version 4.4.3 (Ubuntu 4.4.3-4ubuntu5)