Yes. A temporary is non-const and thus you can call all member
functions on it, including non-const ones. You cannot bind a
temporary to a non-const reference but this is irrelevant to
calling member functions.
On local variables it's possible, on unnamed temporaries not in every
case. This depends on the compiler.
Can you please give an example where it is compiler-dependent
whether you can call a non-const member function on a temporary?
If you have found a compiler which does not allow this, I'm
pretty sure it is an error for that specific compiler.
This line normally leads to errors on many compilers.
A local function declaration is definitely legal according to
the standard. Thus, your statement effectively says that many
compilers are broken. Can you please give the name of at least
two compiler where the above line yields an error? ... after
all, we want to avoid using them.
Calling the
standard constructor is done without the brackets:
String createString;
Given that 'createString()' is clearly used as function later,
I think you got the use wrong. Although I think it was an error
to allow local function declarations, it is legal according to
the current standard.
This line contains also superfluous brackets.
I think you entirely misunderstood what the original poster
did! The first 'createString()' is a function declaration,
not an object declaration. Actually, the name of the function
even indicates what it may be intended to do...
I'm, however, still interested in the broken compilers...