提问者:小点点

C++泛型类错误,出了什么问题?


为什么下面的代码不能编译?

namespace mtm {
    template<class T>
    class Matrix {
    private:
    public:
        class AccessIllegalElement;

    };

    Matrix::AccessIllegalElement{};
}

我正在尝试实现处理错误的内部类

我得到的错误:

“Matrix”不是类,命名空间或枚举

另外,如果我想在AccessIllegalElement内部编写一个打印非法索引的函数,什么更好呢?

1)定义接受一个参数的函数

2)给每个类对象一个名为index成员来保存数据


共1个答案

匿名用户

Matrix是模板,而不是类。 您需要在声明/定义内部项时让编译器知道此模板的模板参数:

template <typename T>
class Matrix<T>::AccessIllegalElement {};

相关问题


MySQL Query : SELECT * FROM v9_ask_question WHERE 1=1 AND question regexp '(c++|泛|型|类|出了|什么问题)' ORDER BY qid DESC LIMIT 20
MySQL Error : Got error 'repetition-operator operand invalid' from regexp
MySQL Errno : 1139
Message : Got error 'repetition-operator operand invalid' from regexp
Need Help?