Method for implementing template functions in C language (continued)

zhaozj2021-02-16  43

Method for implementing template functions in C language (continued):

/ * Define a macro to connect two identifiers: * /

#define make_name (classname, methodname) CALSSNAME ## __ ##MethodName

/ * Template source file: Template.c

* Macro that must be redefined: Theclass

* Other macros that need to be redefined (such as implementation of a search tree, need to compare elements or key-value macros)

*

* /

Int make_name (THECLASS, METHOD1) (int param1, int param2)

{

.

Return 0;

}

Int make_name (THECLASS, METHOD2) (Int param1, int param2)

{

.

Return 0;

}

Int make_name (THECLASS, METHOD3) (int param1, int param2)

{

.

Return 0;

}

... ..

/ * Quote This template file: SAMP1.C * /

#undef theclass

#define theclass class1

#include template.c

/ * end Samp1.c * /

转载请注明原文地址:https://www.9cbs.com/read-28314.html

New Post(0)