1
votes

Well I'm quite sure this is easy :)

I have an abstract tagged type NamedStructure having three fields in the private part of the spec:

  • name (a string)
  • structure (roughly an array)
  • number (an positive)

I then created a subclass Chord which is basically:

type Chord is new NamedStructure with null record;

Playing around with Spark, I need to initialize my chord objects but I face a problem.

Chord_Object : Chord := (NamedStructure'(Name => "", 
                                         Structure => (Others => False), 
                                         Number_Of_Notes => 0) with null record);

doesn't compile and the error message is

scalada-chords.adb:44:53: expected private type "NamedStructure" defined at scalada-namedstructures.ads:52
scalada-chords.adb:44:53: found a composite type

I don't find the correct construction using the extension aggregate and I don't see why. Any idea ?

1

1 Answers

2
votes

The error suggests that NamedStructure is a private type and therefore cannot be initialized using an aggregate. You might try

type Chord is new NamedStructure with null record;

Chord_Object : Chord := (NamedStructure with null record);

although the instance fields of NamedStructure will now remain uninitialized.