问题
Why the following code doesn't compile?
namespace mtm {
template<class T>
class Matrix {
private:
public:
class AccessIllegalElement;
};
Matrix::AccessIllegalElement{};
}
I'm trying to implement the inner class for handling errors
Error I get:
'Matrix' is not a class, namespace, or enumeration
Plus, if inside AccessIllegalElement I want to write a function that prints the illegal index what is preferable?
1) to define a function that takes one parameter
2) to give every class object a member called index to save that data
回答1:
Matrix
is a template, not a class. You need to let the compiler know the template arguments of this template when you declare/define inner items:
template <typename T>
class Matrix<T>::AccessIllegalElement {};
来源:https://stackoverflow.com/questions/62359649/c-generic-class-error-whats-the-problem