an efficient matrix interface in C++

一世执手 提交于 2019-12-12 01:28:16

问题


I am writing a code which uses matrices and advanced operations on them a lot. I am not going to implement a matrix class from the beginning instead I want to have some sort of Matrix abstract class or interface which I define the methods I want for it but it uses another implemented Matrix class through it's core something like:

template <typename T>
class IMatrix
{
public:
    /*some methods and also some operator overloads*/
    virtual T operator() (int r, int c)=0;
};

as the interface for my matrix class and

template <typename T>
class ArdalanMatrix :public IMatrix<T>
{
public:
    ArdalanMatrix(int r,int c, T val=0.){
        numberOfRows = r;
        numberOfColumns = c;
        innerMatrix.resize(r, c, val);
    };
    T operator() (int r, int c) {
        /*implementation*/
    }
private:
    techsoft::matrix<T> innerMatrix;//the inside matrix class 
    int numberOfRows;
    int numberOfColumns;
};

I gave you masters an example of what I want to do but I don't know if it is a good approach or a bad one. what do you recommend to me to do these kind of stuff easily?

int main() {
    IMatrix<double> *M1 = new ArdalanMatrix<double>(5, 5, 0.);
    IMatrix<double> *M2 = new ArdalanMatrix<double>(5, 5, 0.);
    IMatrix<double> *M3;
    M3 = M1 + M2;//overloaded operator "+"
    M3 = M1 * M2;//overloaded operator "*"
}

来源:https://stackoverflow.com/questions/29554383/an-efficient-matrix-interface-in-c

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!