rod*_*igo 6 rust rust-obsolete
从借来的指针教程(破碎),有点修改:
struct Point {x: float, y: float}
fn compute(p1 : &Point) {}
fn main() {
let shared_box : @Point = @Point {x: 5.0, y: 1.0};
compute(shared_box);
}
Run Code Online (Sandbox Code Playgroud)
一切都很好,因为共享框是自动借用的功能.
但做一个特点:
struct Point {x: float, y: float}
trait TPoint {}
impl TPoint for Point {}
fn compute(p1 : &TPoint) {}
fn main() {
let shared_box : @TPoint = @Point {x: 5.0, y: 1.0} as @TPoint;
compute(shared_box);
// ^~~~~~~ The error is here
}
Run Code Online (Sandbox Code Playgroud)
它失败了,(编译器版本0.6)说:
错误:不匹配的类型:预期
&TPoint
但找到@TPoint
(特征存储不同:预期但发现@)
这是编译器中的错误吗?或者是不允许使用特征的借用指针?
如果答案是后者,那为什么呢?
归档时间: |
|
查看次数: |
384 次 |
最近记录: |