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