我试图了解指针在 Swift 中的使用,特别是:Unsafe[Mutable]Pointer
和UnsafeRaw[Mutable]Pointer
. 我有几个关于这个主题的问题。
UnsafePointer <T>
等于const T * Pointer
in ? 在 C中UnsafeMutablePointer <T>
等于T * Pointer
?Unsafe[Mutable]Pointer
和 和有什么不一样UnsafeRaw[Mutable]Pointer
?为什么会这样编译
func receive(pointer: UnsafePointer<Int> ) {
print("param value is: \(pointer.pointee)")
}
var a: Int = 1
receive(pointer: &a) // prints 1
但这给了我一个错误?
var a: Int = 1
var pointer: UnsafePointer<Int> = &a // error : Cannot pass immutable value of type 'Int' as inout argument