Einzelnen Beitrag anzeigen
Ungelesen 05.07.13, 15:42   #3
Quabla
Mitglied
 
Registriert seit: Oct 2010
Beiträge: 296
Bedankt: 151
Quabla ist noch neu hier! | 0 Respekt Punkte
Standard

rows ist ein attribut der klasse matrix. hier mal die klassendeklaration:

Code:
template <typename T>
class Matrix{
  protected:
    unsigned int rows;
    T** m;
  public:
    Matrix(){};                     //empty constructor
    Matrix(unsigned int d);         //constructor for matrix with d rows and collumns
    Matrix(T** _Matrix, unsigned int order);
    Matrix(const Matrix<T> &s);     //copy constructor
    ~Matrix();
    void init();                    //insert values for each component
    void print();                   //prints matrix on console
    Matrix<T> operator*(const Matrix<T> &a);
    Matrix<T> operator+(const Matrix<T> &a);
    Matrix<T> operator-(const Matrix<T> &a);
    vector<T> operator*(const vector<T> &a);
    Matrix<T> operator*(const double &a);
    void setElement(unsigned int i, unsigned int j, T val);
    T getElement(unsigned int i, unsigned int j);
};
edit:
ok jetzt kommt der segfault in einer anderen methode und zwar in

Code:
template<typename T>
void Matrix<T>::setElement(unsigned int i, unsigned int j, T val){
  try{
    if(i>rows-1) throw(DimensionError());
    if (j>rows-1) throw(DimensionError());
    m[i][j]=val;
  }
  catch(DimensionError){
    cerr << "Matrix::setElement::Dimension Error!" << endl;
    exit(1);
  }
}
die ist aber absolut dagegen abgesichert, dass die arraygrenzen überschritten werden. komisch ist auch, dass der matrix destruktor durchläuft (da habe ich testausgaben drin), wenn ich das programm ohne debugger startet. und die matrix wird erst ganz am ende meiner main() rutine entsorgt (ist dynamisch erzeugt). ohne debugger kommt auch kein segfault error sondern:

"This application has requested the Runtime to terminate it in an unusual way. Please contact the applications's support team for more information"

den fehler bekomm ich beim programmieren zum ersten mal^^
Quabla ist offline   Mit Zitat antworten