我有以下代码:
for (Attribute thisAttribute : factor.getAttributes()) {
// blabla
}
Run Code Online (Sandbox Code Playgroud)
哪里有factor.getAttributes()回报List<Attribute>.
显然,只有一个初始调用factor.getAttributes(),然后遍历开始.但是,我不明白为什么只有一个电话.如果我要在常规for()循环的头文件中包含函数调用,我相信它会在每次迭代时进行评估.在这方面,高级循环如何以及为何与众不同?
假设有以下代码:
try {
// Do some boost stuff here
}
catch (const std::exception & stdEx) {
cout << stdEx.what() << endl;
}
Run Code Online (Sandbox Code Playgroud)
问题:
1)我知道代码适用于一些boost异常,即使std :: exception和boost :: exception不在同一个继承路径上.为什么它会起作用呢?
2)它是否适用于所有增强异常?换句话说,是否有例子可以触发低于std :: exception处理程序的boost :: exception处理程序?