I have a template Matrix class:
template <typename T, int row, int col>
class Matrix{};
Inside the class decleration I wrote an execption class, based on std::exception:
class MatrixException: public std::exception
{
private:
const char* errmsg;
public:
MatrixException(const char* msg="")
:errmsg(msg) {}
const char* what() const {return errmsg;}
};
class IllegalOperation: public MatrixException
{
public:
IllegalOperation(const char* msg="")
: MatrixException(msg) {}
};
I tried to use it on one of the class' functions, int the implantation part, like this:
template <typename T, int row, int col>
Matrix<T, row, col>& Matrix<T, row, col>::operator=(const Matrix& mat)
{
if (condition)
{throw IllegalOperation("Matrices sizes don't match");}
// other stuff
return *this;
}
and I get this error message:
looser exception specification on overriding virtual function 'const char* Matrix<T, row, col>::MatrixException::what() const [with T = int; int row = 3; int col = 3]'|
What did I do wrong?
ADDITION: I've tried one of the linked below, and it helped me. Though I did try to find a similar question myself. I've changed the line
const char* what() const {return errmsg;}
to
const char *what() const noexcept {return errmsg;}
and it was ok.
Thanks whoever put the links!