2016-12-05 124 views
0

鑑於這樣的小應用程序文本替換宏

#include "stdafx.h" 

class IGraph 
{ 

}; 

#define NULLWrapper(n) class IG ##nWrapperNULL : public I##n 

class Test : public IGraph 
{ 

}; 

NULLWrapper(Graph) 
{ 

}; 

int main() 
{ 
    IGnWrapperNULL gw; 
    IGGraphWrapperNULL gw; 

    return 0; 
} 

爲什麼Visual Studio的2015年說,IGGraphWrapperNULL是不確定的,而IGnWrapperNULL是正確的? ##n是否應該替換爲我在宏參數中發送的值?

+0

您可以在Visual Studio中生成預處理文件。這會告訴你編譯器看到了什麼。你的兩個主變量不能有相同的名字。 –

回答

3

##不用於「串化」宏參數,它用於連接字符串。正確的定義是:

#define NULLWrapper(n) class IG##n##WrapperNULL : public I##n