本人在用三元组写写稀疏矩阵时,用到了模版结构体,并在另一类中使用该结构体数组,忽略了一个小细节。
//三元组模版 template <class T> struct Triple { int row, col; int value; };
//稀疏矩阵类 template <class T> class Triples { protected: int rows, cols, num; int maxsize; Triple<T> *Elems; public: Triples(int rs = 0, int cs = 0, int size = 0) { rows = rs; cols = cs; maxsize = size; num = 0; Elems = new Triple<T> [maxsize];//这里要写完整"Triple<T>" }
如果写成 “ Elems = new Triple [maxsize];”,会报错,“`Triple' is not a type”