本当に単純な例外クラスを定義しようとしています。非常に単純なので、.h ファイルのみに保持したいのですが、コンパイラは .h ファイルを好みませんthrow()
。コード:
#include <exception>
#include <string>
class PricingException : public virtual std::exception
{
private:
std::string msg;
public:
PricingException(std::string message) : msg(message) {}
const char* what() const throw() { return msg.c_str(); }
~PricingException() throw() {}
};
GCC は次のエラーを返します。
/home/ga/dev/CppGroup/MonteCarlo/PricingException.h:13: error: expected unqualified-id before ‘{’ token
/home/ga/dev/CppGroup/MonteCarlo/PricingException.h:14: error: expected unqualified-id before ‘{’ token
の行の場合throw()
。それを修正する方法はありますか?
編集
問題のあるメソッドの本体を削除しようとしました。
virtual ~PricingException() throw();// {}
そして今、私はさらに奇妙なエラーメッセージを受け取ります:
/home/ga/dev/CppGroup/MonteCarlo/PricingException.h:14: error: looser throw specifier for ‘virtual PricingException::~PricingException()’
/usr/include/c++/4.5/exception:65: error: overriding ‘virtual std::exception::~exception() throw ()’
それは私のスロー指定子を無視しました!