在一个函数A中只有调用另一个函数B,可以把函数A叫做函数B的包装函数.
function A (int i) { B (i) }
这个函数的具体功能是由函数B来实现的,函数A是函数B的接口.
举一个UNIX网络编程的实例:
int Socket(int family, int type, int protocol) { int n; if ( (n = socket(family, type, protocol)) < 0) err_sys("socket error"); // customized error function return (n); }
socket的函数被包装在Socket里面,Socket函数是自定义函数,在里面可以加入简单的error handling.
A wrapper function for a class method is shown in the following code fragment from the bigtime.cpp
example:
/* * ======== clockPrd ======== * Wrapper function for PRD objects calling * Clock::tick() */ void clockPrd(Clock clock) { clock.tick(); return; }
Any additional parameters that the class method requires can be passed to the wrapper function.