gpt4 book ai didi

swift - 二元运算符 '>=' 不能应用于类型 ' (UnsafePointer,Int32) -> UnsafeMutablePointer' 和 'Int' 的操作数

转载 作者:行者123 更新时间:2023-11-30 10:06:31 25 4
gpt4 key购买 nike

我正在尝试使用 for 循环遍历优先级队列

测试用例是这样的

var i = 2
for item in queue {
assert(item == i--)
}

我已经扩展了原来的PriorityQueue像这样

extension PriorityQueue {
private func getItemsInPriorityOrder() -> [I] {
if !isSorted {
isSorted = true
queue.sortInPlace{
return ($0 == nil) ? true :
($1 == nil) ? false :
$0.priority > $1.priority
}
}
var items: [I] = []
for i in 1..<queue.count {
items.append( queue[i].item)
}
return items
}
}

还有

extension PriorityQueue: SequenceType {
public func generate() -> _PriorityQueueIterator<I> {
return _PriorityQueueIterator<I>(items: getItemsInPriorityOrder())
}
}

public struct _PriorityQueueIterator <I> : GeneratorType {
private let items: [I]
private var intex = 0

init(items: [I]){
self.items = items
}

public mutating func next() -> I? {
return index >= items.count ? nil : items[index++] // this giving the error
}
}

我的返回声明return index >= items.count ? nil : items[index++]出现以下错误

error message

我没有明确声明 Int8 类型的任何内容, Int16 ,或Int32

最佳答案

您的属性名为 intex (注意拼写错误),因此函数中的 index 引用了另一个符号,而该符号恰好是名为 的函数索引

关于swift - 二元运算符 '>=' 不能应用于类型 ' (UnsafePointer<Int8>,Int32) -> UnsafeMutablePointer<Int8>' 和 'Int' 的操作数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35636774/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com