std::runtime_error
ストリーミングのサポートを例外に追加するために、から例外クラスを派生させました。解決方法がわからない、clang で奇妙なコンパイラ エラー出力が表示されます。
clang++ -std=c++11 -stdlib=libc++ -g -Wall -I../ -I/usr/local/include Main.cpp -c
Main.cpp:43:19: error: call to deleted constructor of 'EarthException'
throw EarthException(__FILE__, __LINE__)
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
../EarthException.hpp:9:12: note: function has been explicitly marked deleted here
struct EarthException : public Exception<EarthException>
template <typename TDerived>
class Exception : public std::runtime_error
{
public:
Exception() : std::runtime_error("") {}
Exception(const std::string& file, const unsigned line)
: std::runtime_error("")
{
stream_ << (file.empty() ? "UNNAMED_FILE" : file) << "[" << line << "]: ";
}
virtual ~Exception() {}
template <typename T>
TDerived& operator<<(const T& t)
{
stream_ << t;
return static_cast<TDerived&>(*this);
}
virtual const char* what() const throw()
{
return stream_.str().c_str();
}
private:
std::stringstream stream_;
};
struct EarthException : public Exception<EarthException>
{
EarthException() {}
EarthException(const std::string& file, const unsigned line)
: Exception<EarthException>(file, line) {}
virtual ~EarthException() {}
};
}
アップデート:
std::runtime_error("")
これのデフォルトのコンストラクタが指摘されたので、明示的な呼び出しを追加しました=delete
が、エラーは残っています。