#includeThe 3 lines#define CreateFunction( FunctionName, Operator, Type ) \ Type FunctionName( Type a, Type b ) \ { \ return a Operator b; \ } CreateFunction( Add, +, int ) CreateFunction( Sub, -, float ) CreateFunction( Mul, *, long ) using std::cout; using std::endl; int main( ) { cout << "CreateFunction(Add, +, int)" << endl << "10 + 15 = " << Add( 10, 15 ) << endl << "CreateFunction(Sub, -, float)" << endl << "12.4 - 4.34 = " << Sub( 12.4, 4.34 ) << endl << "CreateFunction(Mul, *, long)" << endl << "40 * 123 = " << Mul( 40, 123 ) << endl; return 0; }
CreateFunction( Add, +, int ) CreateFunction( Sub, -, float ) CreateFunction( Mul, *, long )
will be expanded during compile time.
A well-known trick under GNU/C.