宏定义中#和##使用
#include <iostream>
#define PRINT(A) printf("%s : %d\n", #A, A) //#在宏定义中是把后面的参数转换成字符串
#define _CONV_(A,B) A##B //##在宏定义中是把前后两个参数连接起来
#define CONV(A,B) _CONV_(A,B)
#define SHAPE Square
class CShape
{
public:
virtual void show() = 0;
};
class CSquare :public CShape
{
public:
void show() { std::cout << "square" << std::endl; }
};
class CRound :public CShape
{
public:
void show() { std::cout << "round" << std::endl; }
};
int main(int argc, char* argv)
{
int xVar = 5;
PRINT(xVar);
CONV(C,SHAPE) obj;
obj.show();
return 0;
}