Re: Please help me, i got message Assertation falure line 47 _block_type_is_valid(phead->nBlockType) with following code
- From: "Heinz Ozwirk" <hozwirk.SPAM@xxxxxxxx>
- Date: Fri, 24 Feb 2006 10:11:28 +0100
<usman911@xxxxxxxxx> schrieb im Newsbeitrag
news:1140767196.913142.102800@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
//goal: to make a 2 dimentional dynamic array and use it in matrix[...]
multiplication plz help me, //i am using VC++
#include<iostream.h>
class Matrix
{
private:
int *e;
int m,n,sz;
static char count;
char name;
public:
Matrix(int mx = 0,int nx = 0):m(mx),n(nx)
{
sz = m*n;
e = new int[sz];
for(int i = 0;i<sz;i++) //initiaklize d array elements to 0
e[i] = 0;
count++;
name = count; //to have a naming convention of objects, etc A,B,C
}
void insert (int i,int j,int v) //to insert an element in the 2D array
{
if(i<=m && j<=n) //check is refference is ok then insert the item.
e[i * n + j] = v; //convert 2D indexes to one dimention.
else
cout<<"order violation, the matrix has order:"<<m<<'x'<<n<<endl;
}
Either your test or your conversion is wrong. Which one, depends on what
input you are expecting.
If your indexes should be in a range of [1:m] or [1:n] you should use '(i -
1) * n + j -1' to get the offset of that field in your array, and you should
also check, that no negative values or 0 are passed as indexes.
If your indexes should start at 0 as is common in C and C++, the conversion
is ok, but you must check that indexes are non-negative and less than, but
not equal to, m or n.
Of cause you have to fix those bugs everywhere. Write a little function that
converts coordinates into an offset and throws some exception if
coordinates are not valid.
HTH
Heinz
.
- Follow-Ups:
- References:
- Prev by Date: Re: boost (Can it generate hash keys)
- Next by Date: MSXML xmlHttpRequest questions
- Previous by thread: Please help me, i got message Assertation falure line 47 _block_type_is_valid(phead->nBlockType) with following code
- Next by thread: Re: Please help me, i got message Assertation falure line 47 _block_type_is_valid(phead->nBlockType) with following code
- Index(es):
Relevant Pages
|
|