在看codeproject 上的文章ATL Under the Hood 时碰到问题:
……
typedef void (*Fun)(void);
……
Fun pFun = (Fun)*(int*)*(int*)(&objClass+0);
……
本人对typedef void (*Fun)(void);
这句不是行理解,还望大虾指教,谢谢!

解决方案 »

  1.   

    typedef void (*Fun)(void);
    定义一个函数指针类型
      

  2.   

    这种函数的返回值为void,参数为void.
    还有定义成员函数指针类型,例如:
    class CA;
    typedef void (CA::*pmf)();
    定义了一个是类CA的成员函数指针类型。
      

  3.   

    typedef
    typedef type-declaration synonym;The typedef keyword defines a synonym for the specified type-declaration. The identifier in the type-declaration becomes another name for the type, instead of naming an instance of the type. You cannot use the typedef specifier inside a function definition.A typedef declaration introduces a name that, within its scope, becomes a synonym for the type given by the decl-specifiers portion of the declaration. In contrast to the class, struct, union, and enum declarations, typedef declarations do not introduce new types — they introduce new names for existing types.Example// Example of the typedef keyword
    typedef unsigned long ulong;ulong ul;     // Equivalent to "unsigned long ul;"typedef struct mystructtag
    {
       int   i;
       float f;
       char  c;
    } mystruct;mystruct ms;   // Equivalent to "struct mystructtag ms;"typedef int (*funcptr)();  // funcptr is synonym for "pointer
                               //    to function returning int"funcptr table[10];   // Equivalent to "int (*table[10])();"
      

  4.   

    notice this :typedef int (*funcptr)();  // funcptr is synonym for "pointer
                               //    to function returning int"
      

  5.   

    typedef主要用在:
    (1)给某一个类模板实例一个同义词;如typedef vector<int> IntVector;
    (2)像上面定义一个函数指针类型;
    (3)像上面定义一个成员函数指针类型。
      

  6.   

    typedef 用于定义一个类型的别名,在其后紧跟的语句的格式符合“变量的声明语句”的语句格式记“变量的声明语句”为“语句”
    typedef 的意义可以理解为:语句中指定的变量名,是语句中相关变量类型的绰号