[英]How to override non-class members?
I'm having problems trying to override non-class members but I get the error: "'override' can only be specified on class members". 我在尝试覆盖非类成员时遇到问题,但出现错误:“'override'只能在类成员上指定”。
How can I get around this? 我该如何解决?
override func ^(lhs: Int, rhs: Int) -> Int {
return Int(pow(Double(lhs), Double(rhs)))
}
I thought it would work OK, but I didn't expect an error to come up! 我以为可以,但是我没想到会出现错误!
You cannot use override
in only file-scoped place. 您不能仅在文件范围内使用override
。 It uses within class scope. 它在类范围内使用。
Don't use ^
sign to make new function as you want. 不要使用^
符号来创建新功能。 Here below is description of original function ^
: 以下是原始功能^
:
/// Returns the result of performing a bitwise XOR operation on the two given
/// values.
///
/// A bitwise XOR operation, also known as an exclusive OR operation, results
/// in a value that has each bit set to `1` where *one or the other but not
/// both* of its arguments had that bit set to `1`. For example:
///
/// let x: UInt8 = 5 // 0b00000101
/// let y: UInt8 = 14 // 0b00001110
/// let z = x ^ y // 0b00001011
/// // z == 11
///
/// - Parameters:
/// - lhs: An integer value.
/// - rhs: Another integer value.
public static func ^ (lhs: Int, rhs: Int) -> Int
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.