> On 30 Apr 2018, at 10:55, Theo van den Heuvel <vdheu...@heuvelhlt.nl> wrote: > > 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?
Perhaps a recent answer by Jonathan Worthington to a similar question on StackOverflow can be of help here: https://stackoverflow.com/questions/50031400/inheriting-private-attributes-in-perl-6 Liz