#### /tags/rel-1.3.35/Examples/test-suite/octave/member_pointer_runme.m

#
MATLAB | 45 lines | 29 code | 16 blank | 0 comment | 1 complexity | 5d65cb03abdda4efc4dd89ee739e27b6 MD5 | raw file
Possible License(s): LGPL-2.1, Cube, GPL-3.0, 0BSD, GPL-2.0
`````` 1# Example using pointers to member functions
2
3member_pointer
4
5function check(what,expected,actual)
6  if (expected != actual)
7    error ("Failed: %s, Expected: %f, Actual: %f",what,expected,actual);
8  endif
9end
10
11# Get the pointers
12
13area_pt = areapt;
14perim_pt = perimeterpt;
15
16# Create some objects
17
18s = Square(10);
19
20# Do some calculations
21
22check ("Square area ", 100.0, do_op(s,area_pt));
23check ("Square perim", 40.0, do_op(s,perim_pt));
24
25memberPtr = cvar.areavar;
26memberPtr = cvar.perimetervar;
27
28# Try the variables
29check ("Square area ", 100.0, do_op(s,cvar.areavar));
30check ("Square perim", 40.0, do_op(s,cvar.perimetervar));
31
32# Modify one of the variables
33cvar.areavar = perim_pt;
34
35check ("Square perimeter", 40.0, do_op(s,cvar.areavar));
36
37# Try the constants
38
39memberPtr = AREAPT;
40memberPtr = PERIMPT;
41memberPtr = NULLPT;
42
43check ("Square area ", 100.0, do_op(s,AREAPT));
44check ("Square perim", 40.0, do_op(s,PERIMPT));
45
``````