thanks to above.
but i think the A() is a temporary object,
A() is a temporary object is the context of an expression, but it is
the type of a function taking no arguments and returning an A is the
context of a type-id.
the g++ may judgement it is
an object not a function.
It will obviously consider it a temporary in the context of an
expression.
For another example, try this:
class A{};
int main()
{
A a(A());
sizeof(a);
}
"a" above isn't an object at all (you might expect it to be a copy of
a temporary default constructed A), but the declaration of a function
that returns an A, and takes a function pointer parameter that is a
pointer to function taking no arguments and returning an A. Hence the
sizeof call is an error, since a is a function.
i using intel C++ 7.1 to compiling this code, the result is
correct.......
No, intel C++ 7.1 is wrong according to the C++ standard. G++ and
Comeau C++ diagnose the error correctly.
The fact that it is an error is obvious from the standard (my emphasis
added):
1 The sizeof operator yields the number of bytes in the object
representation of its operand. The operand
is either an expression, which is not evaluated, or a **parenthesized
typeid**. The sizeof operator shall not
be applied to an expression that has function or incomplete type, or
to an enumeration type before all its
enumerators have been declared, or to **the parenthesized name of such
types**, or to an lvalue that designates
a bitfield.
In your case you are applying sizeof to the parenthesized name of a
function type, which is illegal.
Tom