0
所以我有這樣一個問題:例外在構造函數C++
class Exception{
private : string message;
public :
Exception();
Exception(string str);
string what();
};
class Something{
public : Something(int m) throw(Exception);
....}
,並在cpp文件:
Exception::Exception()
{
message="cant divide by 0";
}
Exception::Exception(string str)
{
message = str;
}
Exception:string what()
{
return message;
}
,然後我試圖使用它的一些構造
Something::Something(int m) throw(Exception)
{
if (m==0)
{
throw Exception();
}
};
內
and in the main
...
catch(Exception obj){
cout<<obj.what();
}
它顯示「Exception」沒有命名一個類型,'obj'沒有聲明,我不知道爲什麼。
你'Exception'必須從'的std :: exception'繼承是在try/catch語句可用... – Charles
@ C650號,例外是完全沒有問題的方式是。 – 1201ProgramAlarm
你,包括你在主CPP文件中的異常頭文件? – 1201ProgramAlarm