Tutorijali.Net forum

Full Version: Segmentation fault (segfault) c++
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hey ljudi pozz,
mislim da naslov dosta govori ali evo pokusat cu objasniti,
vjezbao sam malo OOP i kada sam pokusao dinamički alocirati prostor preko operatora new javlja mi navedenu gresku, naime program se fino iskompailira ako itko moze pomoći hvala. Palac-gore


Edit : Evo i kod

Code:
#include <iostream>
using namespace std;

class matrix
{
    private:
        int rows;
        int cols;
        float **el;
    public:
        matrix()
        {
            rows = cols = 3;

            *el = new float[rows];
            for(int i=0; i<rows;++i)
                el[i] = new float[cols];

            *el = new float[rows];
            for(int i=0;i<rows;i++)
                el[i] = new float[cols];
            for(int i=0;i<rows; i++)
               for(int j=0; j<cols; j++)
                el[i][j] = 0;
        }
        void ispis()
        {
            for(int i=0;i<rows; i++)
            {
                for(int j=0; j<cols; j++)
                    cout << "\t" << el[i][j];
                cout << endl;
            }

        }
};

int main()
{
    matrix m1;
    m1.ispis();
    return 0;
}
nisi inicijalizirao matrix...
probaj vako, ostalo nisam gledo, ovo sam odmah vidio
Code:
int main()
{
    matrix m1=new matrix();
    m1.ispis();
    return 0;
}
Malo sam morao pročačkati ovako:
Code:
matrix *m1=new matrix;
    m1->ispis();
Hvala prijatelju radi sada super, neznak kako da ti se odužim hvala još jednom spasio si me. He he
Reference URL's