0
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];   }  // [U][B]return statement encountering access violation during runtime , Help!!![/B][/U]
};

Edited by mike_2000_17: Fixed formatting

4
Contributors
3
Replies
4
Views
9 Years
Discussion Span
Last Post by mitrmkar
0

Please use code tags.

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.

0
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];
}
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.