#cpp #gcc
Пытаюсь написать свой класс исключений
class MathException : std::exception
{
public:
MathException(std::string &&whatStr) noexcept : whatStr(std::move(whatStr)) { }
MathException(const std::string &whatStr) noexcept : whatStr(whatStr) { }
~MathException() noexcept;
const char* what() const noexcept override;
private:
std::string whatStr;
};
const char* MathException::what() const noexcept
{
return whatStr.c_str();
}
int main()
try
{
throw MathException("Parse Error");
}
catch(...)
{
}
На что мне компилятор вежливо отвечает:
error: undefined reference to 'typeinfo for MathException'
error: undefined reference to 'MathException::~MathException()'
error: undefined reference to 'vtable for MathException'
the vtable symbol may be undefined because the class is missing its key function
(see go/missingkeymethod)
Ответы
Ответ 1
Решение оказалось до боли смешное. Надо было всего лишь реализовать деструктор, либо сказать компилятору создать его: ~MathException() noexcept = default;
Комментариев нет:
Отправить комментарий