1by1

本人在用三元组写写稀疏矩阵时,用到了模版结构体,并在另一类中使用该结构体数组,忽略了一个小细节。

//三元组模版
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”

 

分类:

技术点:

相关文章:

  • 2021-11-09
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-09-03
猜你喜欢
  • 2022-01-12
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-10-22
  • 2021-11-30
相关资源
相似解决方案