The keyword ‘typedef’ can be used to define short names for type, and can also define a function type of certain returning value type.

//types with short names
typedef unsigned char byte;
typedef std::map<string,string> mapss;
...

//function type
typedef void (*void_returning_function_type)();
typedef int (*int_returning_function_type)();
typedef int (*type3_with_param)(int);
...

//declare some function and put into variable
void test_func() {
  ...
}

int test_func2() {
  return 0;
}

int test_func3(int x) {
  return x*2; //example
}

//variables
void_returning_function_type f1 = test_func;
int_returning_function_type  f2 = test_func2;
type3_with_param             f3 = test_func3;

//example calls
f1();
cout << f2();
cout << f3(99);

 

Advertisements