visual c++ - C++ Object reference not set to an instance of an object -
when try compile following program says "build failed. object reference not set instance of object" . i'm kinda new c++ if can me it'll great . i'm trying out example saw in book don't know whats wrong .
using namespace std; class matrix { int m[3][3]; public: void read(void); void display(void); friend matrix trans(matrix); } void matrix :: read(void) { cout<<"enter elements of 3x3 array matrix : \n"; int i,j; for(i=0;i<3;i++) { for(j=0;j<3;j++) { cout<<"m["<<i<<"]["<<j<<"] ="; cin>>m[i][j]; } } } void matrix :: display(void) { int i,j; for(i=0;i<3;i++) { cout<<"\n"; for(j=0;j<3;j++) { cout<<m[i][j]<<"\t"; } } } matrix trans(matrix m1) { matrix m2; int i,j; for(i=0;i<3;i++) { for(j=0;j<3;j++) { m2.m[i][j] = m1.m[j][i]; } } return(m2); //returning object } int main() { matrix mat1,mat2; mat1.read(); cout<<"\nyou entered following matrix :"; mat1.display(); mat2 = trans(mat1); cout<<"\ntransposed matrix :"; mat2.display(); getch(); return 0; }
1 - insert semi-colon after class definition
2 - insert correct headers
#include <iostream> #include <conio.h>
3 - try getting compiler bit more descriptive regards errors. did mentioned , program ran. try it
Comments
Post a Comment