WvStreams
|
00001 /* 00002 * A WvCallback example. 00003 * 00004 */ 00005 00006 #include "wvcallback.h" 00007 #include <stdio.h> 00008 00009 //Declare a new type of WvCallback called WvMath 00010 //This WvCallbak can point to functions that take 2 input parameters, both of type 00011 //integer, and returns an integer value. 00012 DeclareWvCallback(2, int, WvMath, int, int); 00013 00014 int addition(int a, int b) 00015 { 00016 return a+b; 00017 } 00018 00019 00020 int main() 00021 { 00022 WvMath callback(NULL); //Declare a WvCallback of type WvMath 00023 //callback = wvcallback(WvMath, *this, Math::addition); 00024 callback = addition; // Now callback becomes a function pointer to the addition function 00025 00026 int answer = callback(5, 6); //Bind input parameter values to callback, same 00027 //way as we bind values to the addition function. 00028 00029 printf("answer = %d\n", answer); 00030 00031 00032 } 00033