我有以下课程
#include <string>
class A {
protected:
std::string m1;
int port;
public:
std::string m2;
A(std::string,std::string,int);
};
A::A(std::string _m1,std::string _m2,int _port) : m1(_m1),m2(_m2),port(_port){
}
int main(int argc, char *argv[]){
A("x","y",argc);
}
Run Code Online (Sandbox Code Playgroud)
当用gcc ARM 5.40编译并-Wreorder输出时
a.cpp: In constructor ‘A::A(std::__cxx11::string, std::__cxx11::string, int)’:
a.cpp:9:16: warning: ‘A::m2’ will be initialized after [-Wreorder]
std::string m2;
^
a.cpp:6:8: warning: ‘int A::port’ [-Wreorder]
int port;
^
a.cpp:15:1: warning: when initialized here [-Wreorder]
A::A(std::string _m1,std::string _m2,int _port) : m1(_m1),m2(_m2),port(_port){
^
Run Code Online (Sandbox Code Playgroud)
为什么会产生警告?
威尔m2和port具有缺省值或值分配main …
我想要一个可观察的对象,当取消订阅时,它会调用一个函数,但只有当它取消订阅而没有错误且没有完成时。我尝试构建的可观察对象通常会与另一个可观察对象竞争。我希望当另一个可观察的“获胜”时,这个可观察的执行一个函数。
我尝试了 Finalize 运算符,但它总是执行。
播放.ts
import { timer } from "rxjs";
import { takeUntil, finalize } from "rxjs/operators";
import errorobs$ from "./errorobs";
export default function() {
return timer(10000).pipe(
takeUntil(errorobs$),
finalize(finalFunc)
);
}
function finalFunc() {
console.log("final function executed");
}
Run Code Online (Sandbox Code Playgroud)
错误对象.ts
import { fromEvent } from "rxjs";
import { map } from "rxjs/operators";
export default fromEvent(document.getElementById("errorBtn"), "click").pipe(
map(() => {
throw new Error("my error");
})
);
Run Code Online (Sandbox Code Playgroud)
我在这里做了一个小演示https://codesandbox.io/s/q7pwowm4l6
单击开始以启动“可观察的”。
单击“取消”以使其他可观察的获胜
点击error生成错误