std::exception
から派生してオーバーライドするカスタム例外を作成しようとしていますwhat()
。最初に、次のように書きました。
class UserException : public std::exception
{
private:
const std::string message;
public:
UserException(const std::string &message)
: message(message)
{}
virtual const char* what() const override
{
return message.c_str();
}
};
これは VS2012 では正常に動作しますが、GCC 4.8 では-std=c++11
次のようにコンパイルされません。
エラー: 'virtual const char* UserException::what() const' の緩いスロー指定子</p>
だから私は追加しnoexcept
ます:
virtual const char* what() const noexcept override
これは GCC では正常に動作しますが、Visual Studio ではコンパイルされません (VS 2012 は をサポートしていないためnoexcept
)。
エラー C3646: 'noexcept': オーバーライド指定子が不明です
これに対処するための推奨される方法は何ですか? 同じコードを両方のコンパイラでコンパイルしたいのですが、C++11 機能を使用しているため、異なる .xml でコンパイルすることはできません-std
。