我一直在玩,并对以下代码感到好奇。
@override
Widget build(BuildContext context) {
return new FutureBuilder(
future: getTextFromFile(),
initialData: "Loading text..",
builder: (BuildContext context, AsyncSnapshot<String> text) {
return new SingleChildScrollView(
padding: new EdgeInsets.all(8.0),
child: new Text(
text.data,
style: new TextStyle(
fontWeight: FontWeight.bold,
fontSize: 19.0,
),
));
});
}
Future<String> getFileData(String path) async {
return await new Future(() => "test text");
}
Future<String> getTextFromFile() async {
return getFileData("test.txt");
}
}
问题
struct Bar {
Bar()=delete;
~Bar() { std::cout << "dtor" << std::endl; }
};
struct Foo {
Foo(){}
~Foo() { std::cout << "dtor" << std::endl; }
};
Bar b(); // (A) doesn't call dtor
Foo f(); // (B) doesn't call dtor
Foo f; // (C) calls dtor
Bar b; // (D) error: use of deleted function 'Bar::Bar()'
还有一些魔力吗?