I have a class called Matrix<t>
, My professor asked me to write an exception class:
Matrix::IllegalInitialization
Such that it includes the function what()
, So I wrote (In Matrix.h):
template<class T>
class Matrix<T>::IllegalInitialization {
public:
std::string what() const {
return "Mtm matrix error: Illegal initialization values";
}
};
But I have a problem that this class doesn't inherit Exceptions, how to fix this?
I want the following to work:
try {
Dimensions dim(0,5);
Matrix<int> mat(dim);
} catch (const mtm::Matrix<int>::IllegalInitialization & e){ cout<< e.what() <<endl;
}
Edit: Is this how should my code look like?
template<class T>
class Matrix<T>::IllegalInitialization : public std::exception {
public:
const char* what() const override {
return "Mtm matrix error: Illegal initialization values";
}
};
I am getting:
error: exception specification of overriding function is more lax than base version