C函数重载

#define COUNT_PARMS2(_1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _, ...) _
#define COUNT_PARMS(...) COUNT_PARMS2(__VA_ARGS__, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1)

void cpp_overload1(int p1)
{
	printf("CPP One param: %d
", p1);
}

void cpp_overload2(double *p1, const char *p2)
{
	printf("CPP Two params: %p (%f) %s
", p1, *p1, p2);
}

void cpp_overload3(int p1, int p2, int p3)
{
	printf("CPP Three params: %c %d %d
", p1, p2, p3);
}

#define CAT(A, B) CAT2(A, B)
#define CAT2(A, B) A ## B

#define cpp_overload(...) CAT(cpp_overload, COUNT_PARMS(__VA_ARGS__))(__VA_ARGS__)

http://locklessinc.com/articles/overloading/

原文地址:https://www.cnblogs.com/zl-yang/p/9450471.html