tags:

views:

95

answers:

3
+2  A: 

That is telling you the type of the function's return.

To get the type of the function itself, you want:

typeid(foo)       // note the lack of ()
R Samuel Klatchko
+1  A: 

Wrong on both counts.

1) The sample code tells you that the type of the result of calling foo() is void.

2) Functions are also types.

Noah Roberts
Functions are definitely not types, though they do *have* a type. :)
avakar
@avakar - it's a rather pedantic issue but based on the language of the standard I'd have to disagree. 3.9.2/1 "Compound types can be constructed in the following ways: ... --/functions/..." and 8.3.5/1 "...a type of this form is a /function type/". (slants meant to represent italic type in the text)
Noah Roberts
+4  A: 

typeid does not work with objects. It works with expressions.

typeid returns the type of the expression you supply to it as an argument. The expression can refer to an object, or to something that is not an object. You supplied expression foo() as an argument. This expression has type void. So, you got a result that refers to type void. void, BTW, is not an object type.

Function do have types. If you want to apply typeid to the function itself, the syntax would be typeid(foo). The function-to-pointer conversion is not applied to the argument of typeid, which means that you should get a result that refers to function type itself. Meanwhile, typeid(&foo) will give you a function pointer type id, which is different from typeid(foo).

AndreyT
+1 just to add a little clarity to an already-correct response, the expression `typeid(foo())` first calls the function `foo()` and then does `typeid` on `foo()`'s return value, which is `void`
John Dibling
@John Dibling: This is not entirely accurate. The function is *not* called. `typeid` only evaluates its expression when it has polymorphic class type. In all other cases (including this one) it is similar to `sizeof`, meaning that the argument expression is *not* evaluated.
AndreyT
@AndreyT: Ah, good point.
John Dibling