Advanced usage of C + + macros

Source: Internet
Author: User

#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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.