VC++warning C4290
Mingyuan 2009/5/9
聲明了兩個函數:
int DivideFun(int a,int b) throw(string,int);
double SqrtFun(double a) throw(double);
編譯時間出現警告如下:
warning C4290: C++ exception specification ignored except to indicate a function is not __declspec(nothrow)
原因:
http://msdn.microsoft.com/en-us/library/sa28fef8(vs.80).aspx
Error Message
C++ exception specification ignored except to indicate a function is not __declspec(nothrow)
A function is declared using exception specification, which Visual C++ accepts but does not implement. Code with exception specifications that are ignored during compilation may need to be recompiled and linked to be reused in future versions supporting exception specifications.
http://msdn.microsoft.com/zh-cn/library/sa28fef8(vs.80).aspx
錯誤訊息
忽略 C++ 異常規範,但指示函數不是 __declspec(nothrow)
使用異常規範聲明函數,Visual C++ 接受但並不實現此規範。包含在編譯期間被忽略的異常規範的代碼可能需要重新編譯和連結,以便在支援異常規範的未來版本中重用。
有關更多資訊,請參見 Exception Specifications。
http://msdn.microsoft.com/zh-tw/library/sa28fef8(vs.80).aspx
���息
略� C++ 例外���格,除非�函式�示�非 __declspec(nothrow)
函式是用 Visual C++ 接受但未�作的例外���格宣告的。如果程式�的例外���格在���程中被忽略了,那��程式�可能必�重新��及��,以便在新版的支援例外���格中重�利用。
解決方案:
在函式宣告前加:#pragma warning (disable:4290)
結果如下:
#pragma warning (disable:4290)
int DivideFun(int a,int b) throw(string,int);
double SqrtFun(double a) throw(double);
此方案只是保證編譯器不再彈出警告,但是不能保證編譯器接受異常規範(例外���格宣告、exception specification)。