Go Back  Xtreme Visual Basic Talk > Other Languages > Miscellaneous Languages > Sig Error with simple C++ program


Reply
 
Thread Tools Display Modes
  #1  
Old 07-15-2010, 02:27 PM
Sonic1015's Avatar
Sonic1015 Sonic1015 is offline
Centurion
 
Join Date: Apr 2004
Location: -Not telling :p-
Posts: 136
Default Sig Error with simple C++ program

*sigh* I'm stumped. I'm attempting some practise problems to get familiar with classes, but I keep getting this annoying Sig error, and the my console freezes up. I'm sure that there something stupid I'm doing wrong so any insight would be great. Thanks.



this is matrix.cpp:
PHP Code:
#include "matrix.h"

int main () {
    
matrix m1(22); //this works
    
m1.input(); //this works
    
m1.display(); //this displays
    
m1 m1 m1//debug statements (commented out) all iniate, but...
    
m1.display(); //...never displays this.

this is matrix.h:
PHP Code:
#include <iostream>
using namespace std;

class 
matrix {
    
    
int ** n;
    
    protected:
    
//array, width, & height
    
int x;
    
int y;
    
    public:
    
    
//const & destr
    
matrix(intint);
    ~
matrix();
    
    
//matrix functions
    
void input();
    
void display();
    
friend matrix operator+(matrixmatrix);
    
void operator=(matrix);
};

matrix::matrix(int aint b) {
    
= new int * [a];
    
    for(
int i 0ai++) {
        
n[i] = new int [b];
    }
    
    
a;
    
b;
    
}
//contructor

matrix::~matrix() {

    for(
int i 0x++)
    {
        
delete[] n[i];
    }
    
    
delete[] n;
}
//destructor

void matrix::input() {
    for(
int j 0yj++) {
        for(
int i 0xi++)
            
cin >> n[i][j];
    }
}
//input

void matrix::display() {

    for(
int j 0yj++) {
        for(
int i 0xi++) {
            
cout << n[i][j] << " ";
        }
        
cout << endl;
    }
}
//display

void matrix::operator=(matrix m) {
    
//cerr << "op= start" << endl;
    
    
if((m.!= x) || (m.!= y)) {
        
cerr << "non-compatible matrix" << endl;
    }
    else {
            for(
int i 0xi++) {
                for(
int j 0yj++)  {
                    
n[i][j] = m.n[i][j];
                }        
            }
        }
    
    
//cerr << "op= end" << endl;
}//= operator

matrix operator+(matrix m1matrix m2) {
    
//cerr << "op+ start" << endl;
    
    
if((m1.!= m2.x) || (m1.!= m2.y)) {
        
cerr << "non-compatible addition" << endl;
        
matrix temp(0,0);
        return 
temp;
    }
    
    
matrix temp(m1.xm2.y);
    
    for(
int i 0m1.xi++) {
        for(
int j 0m2.yj++)  {
            
temp.n[i][j] = m1.n[i][j] + m2.n[i][j];
        }        
    }
    
    
//cerr << "op+ end" << endl;
    
return temp;
    
}
// + operator 
compiled with g++. Here is the matrix.exe.stackdump incase it proves useful.

Stack trace:
Frame Function Args
0028C934 756A1184 (00000134, 0000EA60, 00000000, 0028CA58)
0028C948 756A1138 (00000134, 0000EA60, 000000A4, 0028CA3C)
0028CA58 610BADB3 (00000000, 00000134, 0028CA78, 00000000)
0028CB38 610B7A37 (00000000, 00000000, 00000000, 00000000)
0028CB88 610B7E4B (00000C08, 0028CBB0, 6C4F5920, 6C4B65D4)
0028CC48 610B7F71 (00000C08, 00000006, 0028CC78, 610B8015)
0028CC58 610B7FAC (00000006, 0028CE88, 00000007, 0028CCC0)
0028CC78 610B8015 (00CF0568, 00000001, 6C4F5920, 00CD0340)
0028CCE8 610E4ECD (0028CD0C, 0028CD0C, 0028CD18, 000000C0)
0028CD38 004019A3 (0028D008, 00000002, 611A0CCE, 61006DDA)
0028CD78 61006DDA (00000000, 0028CDB0, 610066E0, 7EFDE000)
End of stack trace
__________________
"Sometimes I think the surest Sign that there's intellgent life out there is that none of it has ever tried to visit us." Calvin and Hobbes

Last edited by Sonic1015; 07-15-2010 at 02:33 PM.
Reply With Quote
  #2  
Old 07-18-2010, 08:33 AM
snarfblam's Avatar
snarfblam snarfblam is offline
Contributor

* Expert *
 
Join Date: Apr 2005
Location: Massachusetts
Posts: 571
Default

Does the Display function work prior to performing addition? In other words, what happens if you omit the m1 = m1 + m1;?
__________________
C# _VB.NET _
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:

Powered by liquidweb