Ada 扩展聚合初始化
Ada extension aggregate initialization
好吧,我很确定这很容易:)
我有一个抽象标记类型 NamedStructure 在规范的私有部分有三个字段:
- 名称(字符串)
- 结构(大致是一个数组)
- 数(正数)
然后我创建了一个子类 Chord 基本上是:
type Chord is new NamedStructure with null record;
玩 Spark,我需要初始化我的 chord 对象,但我遇到了问题。
Chord_Object : Chord := (NamedStructure'(Name => "",
Structure => (Others => False),
Number_Of_Notes => 0) with null record);
没有编译,错误信息是
scalada-chords.adb:44:53: expected private type "NamedStructure" defined at scalada-namedstructures.ads:52
scalada-chords.adb:44:53: found a composite type
我找不到使用扩展聚合的正确构造,也不明白为什么。有什么想法吗?
错误表明 NamedStructure
是私有类型,因此无法使用聚合进行初始化。你可以试试
type Chord is new NamedStructure with null record;
Chord_Object : Chord := (NamedStructure with null record);
尽管 NamedStructure
的实例字段现在将保持未初始化状态。
好吧,我很确定这很容易:)
我有一个抽象标记类型 NamedStructure 在规范的私有部分有三个字段:
- 名称(字符串)
- 结构(大致是一个数组)
- 数(正数)
然后我创建了一个子类 Chord 基本上是:
type Chord is new NamedStructure with null record;
玩 Spark,我需要初始化我的 chord 对象,但我遇到了问题。
Chord_Object : Chord := (NamedStructure'(Name => "",
Structure => (Others => False),
Number_Of_Notes => 0) with null record);
没有编译,错误信息是
scalada-chords.adb:44:53: expected private type "NamedStructure" defined at scalada-namedstructures.ads:52
scalada-chords.adb:44:53: found a composite type
我找不到使用扩展聚合的正确构造,也不明白为什么。有什么想法吗?
错误表明 NamedStructure
是私有类型,因此无法使用聚合进行初始化。你可以试试
type Chord is new NamedStructure with null record;
Chord_Object : Chord := (NamedStructure with null record);
尽管 NamedStructure
的实例字段现在将保持未初始化状态。