At the point that base(foo = 0)
executes the DerivedType
class has not been "Created" yet so it can not access the members it defines yet.
The order things happen is like this
- The user calls
new DerivedType()
- The code calls DerivedType's
base(foo = 0)
- The code calls BaseType's implicit
base()
to Object()
- The memory for any fields in
Object
is allocated and then the Object()
constructor is run to completion.
- The memory for any fields in
BaseType
is allocated and then the BaseType(int bar)
constructor is run to completion.
- The memory for any fields in
DerivedType
is allocated and then the DerivedType()
constructor is run to completion.
So you see you are attempting to assign a value to foo
at step 2, but foo
won't exist till step 6.