#ifndef __gnuc__ #error compiler for G++,windows, as if no # #生成的新字符串当成一个宏处理 #endif#define Conn (x, y) x#y//x must be a string, when used, Conn ("2", 3 ), not conn (2,3), 3 can be any type of string//# There are two usages, one is string connection, the other is to connect the generated string as a new macro//new macro must exist//with # #连接中参数中包含已定义的宏时, the macro will not expand the # define STR Test#define Hello (x, y, z) x# #y # #z//First usage Cout< Test program #include <iostream>using namespace std; #ifndef __GNUC__ #error Compiler for g++,windows, as if no # #生成的新字符串当成一个宏处理 #endif#define conn (x, y) x#y// x must be a string, when used, Conn ("2", 3), but not conn (2,3), 3 can be any type of string// ## there are two usages, one is a string connection, The other is to use the string generated by the connection as a new macro// the new macro must exist// # #连接中参数中包含已定义的宏时, the macro does not expand #define hello (x, Y, z) x# #y # #z int main () { cout<<conn ("2", 3) < <endl; // Output 23 // first usage cout<
Advanced usage of C + + macros