编译Nimrod程序的继承类型中未声明的字段

时间:2013-11-01 23:17:43

标签: inheritance compiler-errors nimrod nim

我尝试编译以下代码:

type
  TPerson = object of TObject
    name*: string 
    age: int

  TStudent = object of TPerson
    id: int

var
  student: TStudent
  person: TPerson

student = TStudent(name: "Anton", age: 5, id: 2)

但是我收到以下错误:

  

错误:未声明的字段:'id'

如何宣布id?代码示例直接来自教程。语言中的某些内容是否会在教程中反映出来?


另外,如果我尝试运行以下代码:

student = TStudent(name: "Anton")
echo student.name

我收到以下错误:

  

SIGSEGV:非法存储访问。 (尝试从零读取?)

为什么?

1 个答案:

答案 0 :(得分:3)

我担心你可能会使用Nimrod的最后一个稳定版本(版本0.9.2于2013年5月发布)或旧的git checkout,你强调的是编译器中的错误。现在使用git版本https://github.com/Araq/Nimrod/commit/75ca6eb34fbc983d88961664fd1cfce5f8b44abf,您的第一个和最后一个示例都可以正常工作。在过去几个月中,已经修复了与语言中的对象继承相关的几个错误(issue 179issue 520issue 575issue 563)。

如果你决定自己构建一个git版本(它根本不可怕,虽然有时会有语言中的回归)请use the build instructions from the git,因为该网站可能尚未更新。

相关问题