请教throw后面的 “类名()”是什么意思
请问throw后面的 “类名()”是什么意思?
比如:throw runtime_error( "there is an error! ")
书上throw表达式解释为:throw后跟一个异常类的对象,但是上面语句里throw后面的 "runtime_error( "there is an error! ") "是个对象吗?!
就是对“类名()”的表达不明白
希望大家能帮忙详细的解释一下,先谢了!
------解决方案--------------------
抛出一个runtime_error( "there is an error! ")的异常.
runtime_error( "there is an error! "): 用字符串 "there is an error! "构造一个runtime_error对象
------解决方案--------------------
throw ExceptionClass(“oh, shit! it’s a exception!L “);
例句中,ExceptionClass是一个类,它的构造函数以一个字符串做为参数,用来说明异常。也就是说,在throw的时候,C++的编译器先构造一个ExceptionClass的对象,让它作为throw的返回值,抛——出去。同时,程序返回,调用析构。
------解决方案--------------------
表达式 类名(参数) 的意思是构造一个匿名的对象。
------解决方案--------------------
方便而已。
CComBSTR bstr=CComBSTR( "c string ");
function(bstr);
等于
function(CComBSTR( "c string "));
比如:throw runtime_error( "there is an error! ")
书上throw表达式解释为:throw后跟一个异常类的对象,但是上面语句里throw后面的 "runtime_error( "there is an error! ") "是个对象吗?!
就是对“类名()”的表达不明白
希望大家能帮忙详细的解释一下,先谢了!
------解决方案--------------------
抛出一个runtime_error( "there is an error! ")的异常.
runtime_error( "there is an error! "): 用字符串 "there is an error! "构造一个runtime_error对象
------解决方案--------------------
throw ExceptionClass(“oh, shit! it’s a exception!L “);
例句中,ExceptionClass是一个类,它的构造函数以一个字符串做为参数,用来说明异常。也就是说,在throw的时候,C++的编译器先构造一个ExceptionClass的对象,让它作为throw的返回值,抛——出去。同时,程序返回,调用析构。
------解决方案--------------------
表达式 类名(参数) 的意思是构造一个匿名的对象。
------解决方案--------------------
方便而已。
CComBSTR bstr=CComBSTR( "c string ");
function(bstr);
等于
function(CComBSTR( "c string "));