The error message is a bit misleading. The problem is that
functions do not have
this pointers so they cannot access field variables; they can only access static class variable.
You may also be confusing the compiler by using Array as the class you are defining and as the type of a field variable.
Here's a quick example of the three types of subroutines that can be defined in a class:
class MyArray {
field Array base; // One base for every instance of MyArray
static Array default_base; // All constructor/method/function share a
// single copy of default_base
// *constructor*
// Must return the same type as the class.
// Must return "this"
// Has a "this" pointer so it can access fields.
constructor MyArray new(int size) {
let base = Array.new(123);
return this;
}
// *method*
// May return any type including void.
// Has a "this" pointer so it can access fields.
method void dispose() {
do base.dispose();
return;
}
method Array newAgain(int size) {
do base.dispose();
let base = Array.new(123);
return base;
}
// *function*
// May return any type including void.
// Does not have a "this" pointer so it can only access statics.
function Array getDefault(int size) {
return default_base;
}
}
--Mark