Topic: Nested Classes: addendum
Author: maxtal@physics.su.OZ.AU (John Max Skaller)
Date: Mon, 26 Apr 1993 13:42:27 GMT Raw View
This is an addendum to the proposal for nested functions
that allows the 'address' of a nested function
to be taken in certain circumstances without forming a closure.
Recall that a nested function is a sort of 'member' of a
function, then:
void func() {
void a(int){ .. }
void b(int){ .. }
void c(int){ .. }
...
void (func::* f)(int) = &func::b;
...
(func.*f)(4);
}
This is the exact syntax that would be used if 'func' had been
a class. We will simplify this to:
void func() {
void a(int){ .. }
void b(int){ .. }
void c(int){ .. }
...
void (func::* f)(int) = b;
...
(*f)(4);
}
That is, the 'address' of a nested function can be taken
as a 'pointer to member'.
When a pointer to member is 'executed', it is bound to the current
instance of its environment, as if an ordinary call had been
made.
A function is only viewed as a 'class' or 'namespace' within
the function, so that it is impossible to declare a pointer
to member type for a nested function outside the function
in which it is nested, that is, there is no way to pass
such a pointer to member out of the function.
Thus this extension to the original proposal is both statically
and dynamically secure.
[Preview: closures are taken as follows:
void (closure*)(int) = &b; // or just plain 'b'
and these can be passed out of the function]
--
JOHN (MAX) SKALLER, INTERNET:maxtal@suphys.physics.su.oz.au
Maxtal Pty Ltd, CSERVE:10236.1703
6 MacKay St ASHFIELD, Mem: SA IT/9/22,SC22/WG21
NSW 2131, AUSTRALIA