gcc中使用uuidof

来源:互联网 发布:淘宝被限制交易怎么办 编辑:程序博客网 时间:2024/05/18 01:16

 

前面转了一篇文章仿vc的uuidof: http://blog.csdn.net/zzw_happy/archive/2006/05/22/749407.aspx

现在发现了一个针对gcc的,使用了gcc的typeof:

template< class T>
struct hold_uuidof
{
    
static GUID __IID ;
}
;

/*
    this is a nice one. In MSVC++ u can do:
    __uuidof(Foo) __uuidof(pointer2Foo) __uuidof(refranceofFoo)
    and __uuidof(classAFoo). The GCC typeof() will take care of that
    (get it: use one's extension to implement another)
*/

#define __uuidof( Q ) hold_uuidof< typeof(Q) >::__IID

/*
    use this macro to assosiate a guid to a class/struct.
*/

#define MAKE_UUIDOF_ID( class ,IID ) 
    template
<> 
    GUID hold_uuidof
<class>::__IID = IID;

/*
    This one is the same as above but:
    presupposes an IID_Interface was already defined
*/

#define MAKE_UUIDOF( class ) 
    MAKE_UUIDOF_ID(
class, IID_##class)