Can typeid() be used to pass a function?

Posted by Kerb_z on Stack Overflow See other posts from Stack Overflow or by Kerb_z
Published on 2010-06-08T18:26:18Z Indexed on 2010/06/08 18:32 UTC
Read the original article Hit count: 121

Filed under:

I tried this and got the output as: void

Please explain the following Code:

#include <cstdio>
#include <typeinfo>
using namespace std ;

void foo()
{    }

int main(void)
{
   printf("%s", 
     typeid(foo()).name());// Please notice this line, is it same as typeid( ).name() ?
   return 0;
}

AFAIK: The typeid operator allows the type of an object to be determined at run time.

So, does this sample code tell us that a function that returns void is of *type void*. I mean a function is a method and has no type. Correct?

© Stack Overflow or respective owner

Related posts about c++