Created
September 22, 2017 09:28
-
-
Save lniwn/eed486b13b2dde71f037d838a65f67e3 to your computer and use it in GitHub Desktop.
C++宏默认参数
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
enum | |
{ | |
plain = 0, | |
bold = 1, | |
italic = 2 | |
}; | |
void PrintString(const char* message, int size, int style) | |
{ | |
} | |
#define PRINT_STRING_1_ARGS(message) PrintString(message, 0, 0) | |
#define PRINT_STRING_2_ARGS(message, size) PrintString(message, size, 0) | |
#define PRINT_STRING_3_ARGS(message, size, style) PrintString(message, size, style) | |
#define GET_4TH_ARG(arg1, arg2, arg3, arg4, ...) arg4 | |
#define PRINT_STRING_MACRO_CHOOSER(...) \ | |
GET_4TH_ARG(__VA_ARGS__, PRINT_STRING_3_ARGS, \ | |
PRINT_STRING_2_ARGS, PRINT_STRING_1_ARGS, ) | |
#define PRINT_STRING(...) PRINT_STRING_MACRO_CHOOSER(__VA_ARGS__)(__VA_ARGS__) | |
int main(int argc, char * const argv[]) | |
{ | |
PRINT_STRING("Hello, World!"); | |
PRINT_STRING("Hello, World!", 18); | |
PRINT_STRING("Hello, World!", 18, bold); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment