C++ 宏 ##用法

##表示:把宏参数名与宏定义代码序列中的标识符连接在一起,形成一个新的标识符

 

#define test1(i) test(x##i)  

int main()  
{  

    int x1=1, x2=2, x3=3;  
    test1(1);              // 相当于 test(x1)  
    test1(2);              // 相当于 test(x2)  
    test1(3);              // 相当于 test(x3)  

    return 0;  
}

高级语言写多了,其实不推荐使用c++中的宏

http://www.waitingfy.com/archives/1763

1763

Leave a Reply

Name and Email Address are required fields.
Your email will not be published or shared with third parties.