单井号(#)在宏定义中,不展开参数,直接替换,作用是把传递过来的参数当成字符串进行替换。
双井号(##)又称连接符,它的作用是将参数和前面或后面的子串连接起来,成为一个新的子串。
/
// The one and only application object
CWinApp theApp;
using namespace std;
#define ADDRESS(param) printf("%s参数的地址是:%p\n",#param,param)
#define AGE(param) printf("%s的年龄是:%d\n",#param,param##Age)
#define GENDER(param) printf("%s的性别是:%s\n",#param,param##Gender)
int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])
{
int nRetCode = 0;
int XiaomingAge = 12;
CString XiaomingGender = "Male";
// initialize MFC and print and error on failure
if (!AfxWinInit(::GetModuleHandle(NULL), NULL, ::GetCommandLine(), 0))
{
// TODO: change error code to suit your needs
cerr << _T("Fatal Error: MFC initialization failed") << endl;
nRetCode = 1;
}
else
{
// TODO: code your application's behavior here.
ADDRESS(nRetCode);
AGE(Xiaoming);
GENDER(Xiaoming);
}
return nRetCode;
}