小编had*_*ilq的帖子

什么是“匿名生命周期#1”以及如何以正确的方式定义它?

我希望Handler下面的内容将自己推入列表中

use std::vec::Vec;
use std::rc::Rc;
use std::cell::RefCell;

struct Handler<'a> {
    list: Rc<RefCell<Vec<&'a mut Handler<'a>>>>
}

impl<'a> Handler<'a> {
    fn new(list: Rc<RefCell<Vec<&'a mut Handler<'a>>>>) -> Self {
        Handler { list: list }
    }

    fn push(&mut self) {
        self.list.borrow_mut().push(self)
    }
}

fn main() {
    let list = Rc::new(RefCell::new(Vec::new()));

    let mut h1 = Handler::new(list);
    let mut h2 = Handler::new(list);

    h1.push();
    h2.push();

    // Here the list should contain both h1 and h2

}
Run Code Online (Sandbox Code Playgroud)

但我遇到了这个错误,但我找不到解决方法!

use std::vec::Vec;
use std::rc::Rc;
use std::cell::RefCell;

struct Handler<'a> …
Run Code Online (Sandbox Code Playgroud)

rust

7
推荐指数
1
解决办法
5079
查看次数

Kotlin,子类的辅助构造函数

我试着像这样调用父的第二个构造函数

abstract class A(val i: Int) {
    constructor(c: C) : this(c.i)
}

class B() : A(0) {
    constructor(c: C) : super(c) // error is here
}

class C(val i: Int)
Run Code Online (Sandbox Code Playgroud)

但它会产生Primary constructor call expected错误.子类如何调用父的辅助构造函数?

syntax kotlin

3
推荐指数
1
解决办法
203
查看次数

标签 统计

kotlin ×1

rust ×1

syntax ×1