C++ 文本替换宏

C++ 文本替换宏,c++,C++,考虑到这么小的应用程序 #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

考虑到这么小的应用程序

#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
不应该被我在宏参数中发送的值替换吗?

##
不用于“字符串化”宏参数,它用于连接字符串。正确的定义是:

#define NULLWrapper(n) class IG##n##WrapperNULL : public I##n 
##
不用于“字符串化”宏参数,它用于连接字符串。正确的定义是:

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

您可以在VisualStudio中生成预处理的文件。这将向您显示编译器看到的内容。main中的两个变量不能具有相同的名称。可以在Visual Studio中生成预处理文件。这将向您显示编译器看到的内容。main中的两个变量不能具有相同的名称。