4
經過12年的間歇後回到C++開發。我使用JetBrains的CLion軟件,這非常棒,因爲它提供了關於我的班級設計中可能出現的問題的大量輸入。我在課堂上的構造函數throw statement中得到的警告之一是:Thrown exception type is not nothrow copy constructible
。以下是生成此警告的代碼示例:處理「拋出的異常類型不是無法複製可構造的」警告
#include <exception>
#include <iostream>
using std::invalid_argument;
using std::string;
class MyClass {
public:
explicit MyClass(string value) throw (invalid_argument);
private:
string value;
};
MyClass::MyClass(string value) throw (invalid_argument) {
if (value.length() == 0) {
throw invalid_argument("YOLO!"); // Warning is here.
}
this->value = value;
}
這段代碼可以編譯,我可以對它進行單元測試。但我非常想擺脫這個警告(爲了理解我做錯了什麼,即使它編譯了)。
謝謝
爲什麼使用throw規格?棄用。 https://stackoverflow.com/questions/13841559/deprecated-throw-list-in-c11 –
痛苦'拋出'說明符帶來。太痛苦了。最好沒有,你是。 – user4581301