2015-04-16 37 views
1

我遇到了这个代码,涉及复杂的宏,我想知道这是什么意思复杂的宏

#define DECLARE_LEGACY_TYPES(...) //This all of the macro - I am not holding out on anything 

现在有这个类,因为这

Header file: .h 
    namespace LG_Wrapper 
    { 
     template <LG_Thread Thread> 
     class EffectApplication : public ktApplication 
     { 
     public: 
     static EffectApplication<Thread>& GetInstance(); 
     protected: 
      ..... 
      ..... 
      static boost::recursive_mutex mResource; 
      } 
    } 

    DECLARE_LEGACY_TYPES(EffectApplication); <---- What does this do ? 

我想知道什么影响宏有?

更新: 我收到了很多关于此的问题,因为这个问题给人留下的印象是我没有发布宏的全部内容。没有什么更多的宏观。我希望有。此问题与已关闭的this有关。宏从字面上刚刚结束(...)

#define DECLARE_LEGACY_TYPES(...) 

但没有。这是我在这里的原因之一,因为我不知道如何处理这种情况。这个宏是否没有效果呢?

更多信息:

这是我在另一个文件 我用我的项目设置

LG_WRAPPER_EXPORTS 
LG_THREAD_NAME=GAME 

按照下定义的代码

namespace LG_Wrapper 
{ 

enum LG_Thread 
{ 
    GAME, 
    OTHER 
}; 


/* 
If the library itself is including this file 
*/ 
#ifdef LG_WRAPPER_EXPORTS 

    #ifndef LG_THREAD_NAME 
     #error You must define LG_THREAD_NAME! 
    #endif 

    //Legacy types should not be used internally 
    #define DECLARE_LEGACY_TYPES(...) 

#else // LG_WRAPPER_EXPORTS 

    //Legacy typenames are provided for convenience to the client 
    #define DECLARE_LEGACY_TYPES(ClassType) \ 
     typedef LG_Wrapper::##ClassType##<LG_Wrapper::GAME>    ClassType; \ 

#endif // LG_WRAPPER_EXPORTS 

} 
+1

它只是在这里跳过一些无用的东西。 –

+0

可以将#define与“...”一起使用吗?似乎在那里有一些缺失。 – AlainD

+0

@AlainD:是的,可变宏。 https://gcc.gnu.org/onlinedocs/cpp/Variadic-Macros.html但是这个扩展到完全没有。 –

回答

5

这实际上很常见,但它取决于其他代码中未提及的其他代码ooked在:

#if USING_OLD_COMPILER //when using an older compiler, use this to declare legacy types 
#define DECLARE_LEGACY_TYPES(...) STUFF(__VA_ARGS__)  
#else //new compiler doesn't have to do anything special 
#define DECLARE_LEGACY_TYPES(...) 
#endif 


//in older compilers we had to declare legacy types for this 
//newer compilers don't need this step, so this does nothing at all in them. 
DECLARE_LEGACY_TYPES(EffectApplication); 

我实际上不知道这个宏,所以我不知道它的实际目的。但是,通常看到没有定义类似技巧的宏。