abc

来源:3-4 给函数栓个绳子:指针指向函数

weixin_慕仰6052012

2021-06-26 23:42

abc_

def

写回答 关注

2回答

  • 慕梦前来
    2022-05-26 22:11:45

    这个是什么,没明白

  • 慕梦前来
    2021-07-17 17:23:58
    class Mat
    
    {
    public:
        int row = 0;
        int col = 0;
        float * * mat = nullptr;
    
    private:
        void init(int row, int col)
        {
            if (row && col) {
                mat = new float*[row];
                for (int i = 0; i < row; i++) {
                    mat[i] = new float[col];
                    for (int j = 0; j < col; j++){
                        mat[i][j] = 0;
                        if(i == j){
                            mat[i][j] = 1;
                        }
                    }
                }
            }
        }
    
    public:
        Mat(int row = 0, int col = 0)
        {
            this->row = row;
            this->col = col;
    
            init(row, col);
        }
    
        Mat(const Mat &m)
        {
            this->row = m.row;
            this->col = m.col;
    
            init(row, col);
            for (int i = 0; i < row; i++){
                for (int j = 0; j < col; j++){
                    mat[i][j] = m.mat[i][j];
                }
            }
        }
    
        ~Mat()
        {
            if (mat != nullptr) {
                for (int i = 0; i < row; i++){
                    if (mat[i]) {
                        delete[] mat[i];
                        mat[i] = nullptr;
                    }
                }
                if (mat){
                    delete[] mat;
                }   
                mat = nullptr;
            }
        }
    
        Mat & operator = (const Mat &m)
        {
            if (mat != nullptr) {
                for (int i = 0; i < row; i++){
                    if (mat[i]) {
                        delete[] mat[i];
                        mat[i] = nullptr;
                    }
                }
                if (mat){
                    delete[] mat;
                }
                mat = nullptr;
            }
    
            row = m.row;
            col = m.col;
    
            init(row, col);
            for (int i = 0; i < row; i++){
                for (int j = 0; j < col; j++){
                    mat[i][j] = m.mat[i][j];
                }
            }
    
            return *this;
        }
    
        Mat operator * (const Mat &m)
        {
            EyerMat res(row, m.col);
            
            for (int i = 0; i < res.row; i++) {
                for (int j = 0; j < res.col; j++) {
                    res.mat[i][j] = 0.0f;
                }
            }
    
            if (m.row != col){
    
            }
            else {
                for (int i = 0; i < res.row; i++) {
                    for (int j = 0; j < res.col; j++) {
                        for (int k = 0; k < res.row; k++) {
                            res.mat[i][j] += mat[i][k] * m.mat[k][j];
                        }
                    }
                }
            }
                
            return res;
        }
    }


趣味 C++ 进阶

本课程是 C++ 的进阶课程,继续趣味学习之旅,带你探索 C++ 的高级用法。

14705 学习 · 44 问题

查看课程