小编Ant*_*oro的帖子

Python黑色格式化程序与VSCode中的规则flake8 W503冲突

每当有一个内联断言规则需要针对 bool 语句进行验证时,在 VSCode 中使用 python black 格式化程序都会破坏该行,导致 flake8 发出有关规则 W503 的警告

line break before binary operatorflake8(W503)

assert (
      ...
      != ...
)
Run Code Online (Sandbox Code Playgroud)

有没有解决这个问题而不是忽略该规则的方法?

python flake8 python-black

13
推荐指数
1
解决办法
1万
查看次数

返回非常量引用会导致绑定引用错误

我已经使用弱指针和智能指针实现了一个双链表。该计划是工作,但我有关于怀疑constgetPrev签名方法。如果我把 const一个方法签名的结尾,它会导致绑定引用错误

error: binding reference of type 'std::weak_ptr<Node<Integer> >&' to 'const std::weak_ptr<Node<Integer> >' discards qualifiers
         return prev;
Run Code Online (Sandbox Code Playgroud)

这样做的目的不是const标记*thisconst吗?根据我的理解,返回类型是非常量的。

这是代码,main.cpp

#include <memory>
#include <iostream>
#include "DoubleLinkedList.h"

class Integer {
private:
    int number;
public:
    Integer(int number) : number(number) {}

    int get() { return number; }

};

int main() {

    DoubleLinkedList<Integer> list;
    list.insert(Integer(1));
    list.insert(Integer(2));
    list.insert(Integer(3));
    list.insert(Integer(4));
    list.insert(Integer(5));


    return 0;
}
Run Code Online (Sandbox Code Playgroud)

DoubleLinkedList.h

#include <memory>
#include <vector>
#include <iostream>

template <typename T> …
Run Code Online (Sandbox Code Playgroud)

c++

5
推荐指数
1
解决办法
488
查看次数

使用 MainScope() 和 requireActivity().lifecycleScope 在片段内启动协程有什么区别?

这对于启动需要在片段生命周期之后继续的操作(例如数据库写入)有意义吗?

代码示例:

requireActivity().lifecycleScope.launch {
         // suspend function invocation
}

MainScope().launch { 
        // suspend function invocation
}
Run Code Online (Sandbox Code Playgroud)

android android-fragments android-activity kotlin-coroutines

5
推荐指数
1
解决办法
998
查看次数

启动线程在指针初始化时导致分段错误

为什么*y = 20只有启动两个“空”线程时,这段代码才会导致分段错误?

int main(int argc, char **argv) {

    int x = 10;
    int *y;
    *y = 20;

    std::thread t1([]{});
    std::thread t2([]{});

    t1.join();
    t2.join();

    return 0;
}
Run Code Online (Sandbox Code Playgroud)

c++ multithreading pointers segmentation-fault

-4
推荐指数
1
解决办法
85
查看次数