| | |
problem in constructing two dimensional array in c++ using classes
![]() |
class matrix
{
int **p;
int d1,d2;
public:
matrix(int x,int y); //constructor allocates block of specified size
/*I am not specifying contructor code*/
void get_element(int i,int j,int value)
{ p[i][j]=value; }
int put_element(int i,int j)
{ return p[i][j]; } // return statement encountering access violation during runtime , Help!!!
};
{
int **p;
int d1,d2;
public:
matrix(int x,int y); //constructor allocates block of specified size
/*I am not specifying contructor code*/
void get_element(int i,int j,int value)
{ p[i][j]=value; }
int put_element(int i,int j)
{ return p[i][j]; } // return statement encountering access violation during runtime , Help!!!
};
•
•
Join Date: Jan 2008
Posts: 3,765
Reputation:
Solved Threads: 493
Please use code tags.
You're going to have to post more code unless someone else sees something wrong with what you posted. I don't. I'm guessing the problem is in your constructor.
C++ Syntax (Toggle Plain Text)
class matrix { int **p; int d1,d2; public: matrix(int x,int y); //constructor allocates block of specified size /*I am not specifying contructor code*/ void get_element(int i,int j,int value) { p[i][j]=value; } int put_element(int i,int j) { return p[i][j]; } // return statement encountering access violation during runtime , Help!!! };
You're going to have to post more code unless someone else sees something wrong with what you posted. I don't. I'm guessing the problem is in your constructor.
•
•
Join Date: Nov 2007
Posts: 978
Reputation:
Solved Threads: 208
C++ Syntax (Toggle Plain Text)
int put_element(int i, int j) { // check here that both i and j are within the bounds // you currently have allocated ... // And remember that indexes are zero-based, i.e. // if you have 'int arr[2]', the last valid index is 1 (not 2) return p[i][j]; }
![]() |
Other Threads in the C++ Forum
- Previous Thread: SDL_toypiano
- Next Thread: copy a file
| Thread Tools | Search this Thread |
api array based binary bitmap business c++ c/c++ char class classes code coding commentinghelp compile console conversion count decide delete deploy desktop developer directshow dll download dynamic dynamiccharacterarray email encryption error file forms fstream function functions game givemetehcodez graph guess gui homeworkhelp homeworkhelper iamthwee ifpug ifstream incrementoperators infinite input int integer java lib linkedlist linker loop looping loops map math matrix memory multiple news node number numbertoword output parameter pointer problem proficiency program programming project python random read recursion reference rpg string strings temperature template templates test text text-file tree url variable vector video win32 windows winsock word wordfrequency wxwidgets






