Hi all,

trying to make sense of the following excerpt from the documentation on object construction:

Due to the default behavior of BUILDALL and BUILD submethods, named arguments to the constructor new derived from Mu can correspond directly to public attributes of any of the classes in the method resolution order, or to any named
 parameter of any BUILD submethod.


I would like to build a class A and subclasses AB and more such that AB and friends differ in the default attribute values. On the basis of the docs I expected this to work:

#<code>
class A {
  has Int $.a;
  method sayit() { say $!a }
}

class AB is A {
  submethod BUILD(:$!a = 17){}
}


my $ab = AB.new().sayit;
#</code>

however. I get "Attribute $!a not declared in class AB", which makes sense.
How should I write this instead?

Thanks


--
Theo van den Heuvel
Van den Heuvel HLT Consultancy

Reply via email to