zoukankan      html  css  js  c++  java
  • 一个错误,谁来看看

    #include <iostream>
    #include <cstdlib>
    using namespace std;
    const int DefaultSize=100;
    template <class T>
    struct Trituple{
        int row,col;
        T value;
        Trituple<T>& operator =(Trituple<T>& x){
            row=x.row;col=x.rol;value=x.value;
        }
    };
    template <class T>
    class SparseMatrix{
    public:
        friend ostream& operator <<(ostream& out,SparseMatrix<T>& M);
        friend ostream& operator >>(ostream& in,SparseMatrix<T>& M);
        SparseMatrix(int maxSz=DefaultSize);
        ~SparseMatrix(){delete []smArray;}
        SparseMatrix<T>& operator =(SparseMatrix<T>& x);
        SparseMatrix<T> trans();
        SparseMatrix<T> Add(SparseMatrix<T>& x);
    private:
        int Rows,Cols,Terms;
        Trituple<T> *smArray;
        int maxTerms;
    };
    template <class T>
    SparseMatrix<T>::SparseMatrix(int maxSz):maxTerms(maxSz){
        smArray=new Trituple<T>[maxSz];
        Rows=Cols=Terms=0;
    }/*
    template <class T>
    ostream& operator <<(ostream& out,SparseMatrix<T>& M){
        out<<"rows="<<M.Rows;
        out<<"clos="<<M.Cols;
        out<<"terms="<<M.Terms;
        for(int i=0;i<M.Terms;i++){
            out<<"M["<<M.smArray[i].row<<"]["<<M.smArray[i].col<<"]="<<M.smArray[i].value;
        }
        return out;
    }*/
    //下面这段本来是没有的
    ostream& operator <<(ostream& out,SparseMatrix<int>& M){ out<<"rows="<<M.Rows; out<<"clos="<<M.Cols; out<<"terms="<<M.Terms; for(int i=0;i<M.Terms;i++){ out<<"M["<<M.smArray[i].row<<"]["<<M.smArray[i].col<<"]="<<M.smArray[i].value; } return out; } int main(){ SparseMatrix<int> s(100); cout<<s; return 0; }

    这个吧那一段注释了,按道理是用T的,可是编译不过,不知道是为什么?????

  • 相关阅读:
    SLAB
    /proc/vmstat 详解
    swap空间可以有效缓解内存压力
    内存问题排查手段及相关文件介绍
    buddyinfo 内存碎片数据采集
    取得Linux系统的各种统计信息
    HTML的常用总结
    采用jquery同django实现ajax通信
    Django的quarySet
    Django-MySQL数据库使用01
  • 原文地址:https://www.cnblogs.com/bq12345/p/3011259.html
Copyright © 2011-2022 走看看