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: Sat, 25 Feb 2006 10:06:01 +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;
A class with raw pointers almost allways requires an assignment operator and
copy constructor.
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;
}
//returns value of a particular pos /**********I get error in this
function i think*****/
int & pull (int i,int j) //retuns the number after converting 2D
Change this declaration to
int pull(int i, int j) const
or add another pull function, which can work on a const Matrix and returns
the value of the specified element (or a const reference).
indexes to one D index
{
if(i<=m && j<=n)
{
return e[i * n + j]; //conversion of 2D indexes to 1D, n is the 2nd
Dimention
}
else
{
cout<<"order violation, the matrix has order:"<<m<<'x'<<n<<endl;
return e[0];
}
}
//will store its order into two varables passes as refference by the
calling func
void order(int &M,int&N)
void order(int& M, int& N) const
{
M = m;
N = n;
}
Matrix operator * (Matrix B) // matrix multiplication, works fine but
Matrix operator*(Matrix const& B) const
error comes in this
//block when pull is
called
{
if(n == B.m)
{
Matrix C(m,B.n);
for(int i=0;i<m;i++)
for(int j=0;j<B.n;j++)
for(int k=0;k<n;k++)
C.insert(i,j,C.pull(i,j) + this->pull(i,k) * B.pull(k,j));
return C;
}
else
{
Matrix null(m,B.n);
cout<<"order mismatch"<<endl;
return null;
}
}
void setMatrix()
{
int temp;
for(int i = 0;i<m;i++)
for(int j= 0;j<n;j++)
{
cout<<"Enter values of Matrix "<<name<<' '<<m<<'x'<<n<<" matrix at:
"<<i+1<<','<<j+1<<" :";
cin>>temp;
this->insert(i,j,temp);
}
}
void show()
void show() const
{
for(int i = 0;i<m;i++)
{
for(int j = 0;j<n;j++)
cout<<this->pull(i,j)<<'\t';
cout<<endl;
}
}
~Matrix()
{
delete []e;
count--;
}
Remember the "rule of three"
};
char Matrix::count = 64;
/********************************************************************************/
int main (void)
{
Matrix A(2,3),B(3,2),C(2,2);
A.setMatrix();
B.setMatrix();
C = A*B;
C.show();
A.show();
cout<<endl;
B.show();
cout<<endl;
C.show();
return 0;
}
///PLEASE any help will be greatly apriciated, i get error of
//Assertation falure at line 47 of dbgdl.cpp
//Expression:_block_type_is_valid(phead->nBlockType)
HTH
Heinz
.
- References:
- Prev by Date: Re: 8.3 format file name questions.
- Next by Date: Re: Fast array indexing with pointers
- Previous by thread: Re: Please help me, i got message Assertation falure line 47 _block_type_is_valid(phead->nBlockType) with following code
- Next by thread: boost (Can it generate hash keys)
- Index(es):
Relevant Pages
|
|