代码:
#include<iostream>
using namespace std;
void foo() throw(char) {throw 'a';}
int main() try {
void (*pf)() throw(float);
pf = foo; // This should NOT work
pf();
}
catch(const char& c){cout << "Catched ::> " << c << endl;}
为什么即使foo
的异常规范与函数指针pf
不同,也可以将foo
传递给pf
?这是编译器的错误吗?
try-catch
不是函数声明
的一部分。 - Anirudha