C ++
Objects of this class cout messages when they are created and destroyed. I tried to create a temporary object using only the class name declaration, but it gave an unexpected result.
In # 1, I create a temporary unnamed object using parentheses.
In # 2, I create a temporary nameless object using a single initialization.
I did not know if compilation # 3 would be. I only thought that if No. 3 would compile, this would mean creating a temporary nameless object. It compiles, but the object is not created, as can be seen from the emptiness of the console output at # 3. What's going on here?
Console exit:
#1: constructed destroyed #2: constructed destroyed #3:
Note: This was compiled in VC11 with the November 2012 CTP. It does not compile in g ++ 4.8.0 or clang 3.2, which gives error: declaration does not declare anything [-fpermissive] and fatal error: 'iostream' file not found respectively.
source share