2 Modular functions (no this)
3 ===========================
6 The declaration qualifier 'modular', can be used to declare
7 member functions that do not have "this", and cannot access any
8 class member. So what is the meaning of making a function
9 a member if it is not interested in accessing the data of the
13 The one case where modular functions make sense is when they are
14 virtual. They can be used to emulate plain callback functions which
15 are attached to the object but, do not indeed, need any data from
19 class StandardFractal {
20 virtual modular bool iszero (float f)
21 { return fabsf (f) < 0.01f; }
22 void do_calculations (); // calls iszero
25 class PreciseFractal : StandardFractal {
27 { return fabsf (f) < 0.0001f; }
30 Modular functions are faster to call (one argument less) and the
31 progam size is smaller.
33 A modular function, because it does not have "this" cannot access
34 any data members of the class, cannot call other no-modular member
35 functions and cannot use anything virtual (variables or functions).
36 It can call other modular functions though (but not virtual).
38 Modular functions can be called without an object instance.
39 If you don't have such an instance and still want to call a modular
40 function, this can be done with the syntax <class>.<func> ();
42 Another application of modular functions, is together with
43 "auto functions" and the new reserved word "_CLASS_", to
44 access virtual variables. For example:
47 virtual int active, allocated, freed;
49 return _CLASS_.active + _CLASS_.freed - _CLASS_.allocated;
58 int total = A.sum () + B.sum ();
61 Finally, a modular function which is neither virtual or auto, is
62 possible but little useful. It could be used to emulate c++ namespaces