Matrix Arithmetic using Vectors in C++ causing segmentation faults

后端 未结 7 1195
执笔经年
执笔经年 2021-01-15 02:37

I\'m having some issues passing vectors to functions. My concern is not with my logic itself, as if I need to adjust later I will. My program requirements state that I must

相关标签:
7条回答
  • 2021-01-15 02:55

    Your program segfault because you create matrix with a size of (0,0). When you try to set elements : segfault :)

    Suggestions :

    • use a matrix library :)
    • if you want to learn : create a Matrix object that you will create with the correct size
    • please avoid globals !
    • flag your question as homework ;)

    For your class try to implement something like :

    class Matrix
    {
        public:
        Matrix(unsigned rows, unsigned columns);
        void add(const Matrix&)
        void print();
    
        // etc.
    };
    

    my2c

    0 讨论(0)
提交回复
热议问题