没有重载匹配'类型为Person的数组(Person)#+'

Ale*_*nox 2 crystal-lang

所以我刚开始学习Crystal,因为我喜欢Ruby和C,但我还是无法掌握语法.我想我很亲密,但我坚持这个错误.
no overload matches 'Array(Person)#+' with type Person Overloads are: - Array(T)#+(other : Array(U)) people += Person.new("Person#{id}")

这是代码.

class Person
    def initialize(name : String)
        @name = name
        @age = 0
    end

    def name
        @name
    end

    def age
        @age
    end
end

people = [] of Person
counter = 0
id = 0

loop do
    id+=1
    people += Person.new("Person#{id}")

    counter+=1
    break if counter = 5
end

puts(people)
Run Code Online (Sandbox Code Playgroud)

我究竟做错了什么?提前致谢!

WPe*_*0EU 5

你正试图把一个数组和一个人放在一起.但您只能将Array添加到Array.

要解决它,你应该使用Array#<<,像这样: people << Person.new("Person#{id}")

注意:检查你的第25行,它应该是break if counter == 5