我已经在DDJ中阅读了关于范围保护的文章(通用:改变你编写异常安全代码的方式 - 永远),我理解它们的常用用法.
但是,常见的用途是在堆栈上为特定操作实例化特定堆栈保护,例如:
{
FILE* topSecret = fopen("cia.txt");
ON_BLOCK_EXIT(std::fclose, topSecret);
... use topSecret ...
} // topSecret automagically closed
Run Code Online (Sandbox Code Playgroud)
但是,如果我想在运行时安排清理操作,例如当我有一个循环时,该怎么办:
{
vector<FILE*> topSecretFiles;
for (int i=0; i<numberOfFiles; ++i)
{
char filename[256];
sprintf(filename, "cia%d.txt", i);
FILE* topSecret = fopen(filename);
topSecretFiles.push_back(topSecret);
ON_BLOCK_EXIT(std::fclose, topSecret); // no good
}
}
Run Code Online (Sandbox Code Playgroud)
显然,上面的例子不起作用,因为topSecret它将与for范围一起关闭.我想要一个范围保护模式,我可以很容易地排队清理操作,我确定在运行时需要它.有这样的东西吗?
我无法将范围保护对象推入标准队列,导致原始对象(我正在推送的对象)在此过程中被解除.如何推送堆分配的堆栈保护并使用在dtor上删除其成员的队列?有没有人有更聪明的方法?
如何在 Inno Setup Pascal 脚本中迭代 MULTI_SZ 字符串?例如超过返回的值RegQueryMultiStringValue
我做了一切"正确":
用LOCAL_MODULE := libfoojni/Android.mk 创建了我的JNI模块
叫 System.loadlibrary("libfoo")
声明了方法的正确签名,甚至用它进行了双重检查 javah
但仍然有一个UnsatisfiedLinkError消息的例外:
无法加载libfoo:findLibrary返回null
如何"触摸"文件,即从InnoSetup(Pascal)脚本中将其上次修改时间更新为当前时间?
使用以下代码:
let tableView = ...
let oldSize = tableView.contentSize // header + all rows + footer
tableView.tableHeaderView.bounds.height -= 10
tableView.tableFooterView.bounds.height -= 10
Run Code Online (Sandbox Code Playgroud)
你会看到:
assert(tableView.contentSize != oldSize) // ERROR: assertion fails
Run Code Online (Sandbox Code Playgroud) inno-setup ×2
pascal ×2
android ×1
android-ndk ×1
c++ ×1
ios ×1
scopeguard ×1
scripting ×1
uikit ×1
uitableview ×1