我的一个学生提交了一些类似于下面的C++代码.代码编译并运行,但该throw
语句产生以下消息:
抛出'int'实例后调用terminate
如果我创建函数void
编译器抱怨
无效使用'void'
在包含该throw
声明的行上(预期).
class TestClass
{
public:
int MyException()
{
return 0;
}
void testFunc()
{
throw MyException();
}
};
int main(int argc, char** argv)
{
TestClass tc;
tc.testFunc();
return 0;
}
Run Code Online (Sandbox Code Playgroud)
那么,MyException
由于代码是"正确的" ,C++如何解释?