WvStreams
wvcallbackex2.cc
1
2#include "wvcallback.h"
3#include <stdio.h>
4
5//Declare a new type of WvCallback called WvMath
6//This WvCallbak can point to functions that take 2 input parameters, both of
7//type integer, and returns an integer value.
8DeclareWvCallback(2, int, WvMath, int, int);
9
10class Math
11{
12 public:
13 int addition(int a, int b);
14};
15
16int Math::addition(int a, int b)
17{
18 return a+b;
19}
20
21
22int main()
23{
24 WvMath callback(NULL); //Declare a WvCallback of type WvMath
25 Math object;
26 callback = wvcallback(WvMath, object, Math::addition); //Here callback becomes a pointer
27 //to the member function (addition) that belongs to the WvMath class
28
29 int answer = callback(5, 6); //Bind input parameter values to callback,
30 //same way as we bind values to the addition function.
31
32 printf("answer = %d\n", answer);
33
34}
35