The following C ++ code does nothing (using GCC 4.4.3) - it does not print text:
struct MyStruct { MyStruct() { cout << "Hello" << endl; } };
void foo() {
MyStruct ();
}
I think this is not so obvious ... Not to mention the danger of forgetting to give a variable name. Is there a compiler option / warning to prohibit compilation of such code, or is there a hidden secret behind its permission?
Edit: Sorry. The version above MyStruct();completes printing. Version that does not print:
void bar() {
MyStruct a();
}
So now I'm a little confused.
source
share