我正在尝试使用以下代码进行订阅,但它不起作用.
import { Platform } from 'ionic-angular';
@Page({
templateUrl: 'build/pages/test.html',
})
export class Test{
constructor(private platform: Platform) {
this.platform.pause.subscribe(() => {
console.log('paused')
});
}
}
Run Code Online (Sandbox Code Playgroud)
我正在使用Ionic 2和TypeScript,Angular 2.正如platform.pauseIonic 2提供的EventEmitter,我想它应该可以订阅.但是,当我将应用程序放到后台时,console.log('pause')不会被解雇.
我应该添加Platform到提供商或类似的东西?另外,this.platform不是null.this.platform.ready().then(()=>{console.log('ready')})工作得很好.
请考虑以下代码:
template <typename T, typename P, T P:: *s> struct H {};
struct AA { int i; };
int main()
{
typedef int AA::*PI;
constexpr PI pi = &AA::i;
H<int, AA, &AA::i> h1; // OK
// H<int, AA, pi> h2; // compile error
}
Run Code Online (Sandbox Code Playgroud)
我有成员指针pi指向AA::i.
pi是一个constexpr变量.为什么我不能将它用作模板参数,即使&AA::i直接使用也可以?
我写
let fact x =
let result = ref 1 in
for i = 1 to x do
result := !result * i;
Printf.printf "%d %d %d\n" x i !result;
done;
!result;;
Run Code Online (Sandbox Code Playgroud)
在名为"Moduletest.ml"的文件中,和
val fact : int -> int
Run Code Online (Sandbox Code Playgroud)
在名为"Moduletest.mli"的文件中.
但是,他们为什么不工作?
当我试图在ocaml中使用时,
Moduletest.fact 3
Run Code Online (Sandbox Code Playgroud)
它告诉我:
Error: Reference to undefined global `Moduletest'
Run Code Online (Sandbox Code Playgroud)
发生了什么?
谢谢.
class A{
int a;
A(){
this.a = 100;
}
}
//in main, we have:
A a = new A(), b = new A();
//and
String str0 = "123", str1 = "123";
Run Code Online (Sandbox Code Playgroud)
为什么str0和str1的哈希码是相同的,但不是a和b?
struct t{
int a;
t(int i){
a = i;
}
};
void test(t**& ppT){
t *pT = (t*)malloc(sizeof(t));
pT->a = 100;//works
t *pT = new t(100);//doesn't work
ppT = &pT;
}
Run Code Online (Sandbox Code Playgroud)
我有一个名为t的结构,以及一个名为test的函数.
在main()中,我有
t **ppT = NULL;
test(ppT);
cout << ppT << " " << *ppT << endl;
cout << ppT << " " << *ppT << endl;
Run Code Online (Sandbox Code Playgroud)
如果我在测试中使用malloc ,它可以工作.但是,如果我在测试中使用new ,它会告诉我
0049FCC8 0074C378
0049FCC8 CCCCCCCC
Run Code Online (Sandbox Code Playgroud)
有什么问题?此外,我使用Visual Studio 2013作为我的编译器.
例如,我们maximum [1,2,3]返回列表中的最大元素.
但如果我们在本地重新定义它,
let maximum xs = head xs
Run Code Online (Sandbox Code Playgroud)
(我知道这很奇怪,但没关系)
我们怎么称呼最初的最大功能?
我有以下Haskell代码:
two :: Integer -> Integer
two i = toInteger(2 ** i)
Run Code Online (Sandbox Code Playgroud)
为什么不工作?