#ifndef MAT_H #define MAT_H // // mat.h - base class for dense and sparse matrices // // Note that operator+ must return a matrix by value, but // dense matrices and sparse matrices are not the same size. // So mat::operator+ can't simply return a mat. It must // defer specifying the return type until we know what will // be returned. #pragma warning(disable : 4786) #include #include #include // // T - type of data in matrix, usually double // U - type of matrix returned by operator+ // depends on the type of the operational // derived class // template class mat { public: // constructors go here virtual U operator+(const U &v)=0; // lots of other stuff go here }; //----< dense matrix is vector of vectors >-------------------- template class dMat : public mat { public: virtual dMat operator+(const dMat &dm); protected: std::vector< std::vector > array; }; //----< addition >--------------------------------------------- template dMat dMat::operator+(const dMat &dm) { std::cout << "\n invoking dense matrix addition\n\n"; dMat sum; return sum; } // //----< sparse matrix is list of lists >----------------------- template class sMat : public mat { public: virtual sMat operator+(const sMat &sm); protected: std::list< std::list > adjacList; }; //----< addition >--------------------------------------------- template sMat sMat::operator+(const sMat &dm) { std::cout << "\n invoking sparse matrix addition\n\n"; sMat sum; return sum; } #endif