I have a class Dataset as given below
template <class StorageType> class Dataset
{
private:
class Row
{
private:
uInt32 NCol;
StorageType *Data;
public:
Row(){
Data = NULL;
}
void SetCol(uInt32 Col){
if((Data = new StorageType[Col]) == NULL)
{
cout << "Dataset::memory exhausted ... exiting" << endl;
exit(1);
}
NCol = Col;
}
~Row(){
if(Data != NULL)
{
delete []Data;
}
}
StorageType &operator[](uInt32 Col){
return Data[Col];
}
};
Row *Array;
uInt32 NRow;
uInt32 NCol;
public:
Dataset(uInt32 Row, uInt32 Col)
{
if((Array = new Row[Row]) == NULL){
cerr << "Dataset::memory exhausted ... exiting" << endl;
exit(1);
}
register uInt32 i;
for(i = 0;i < Row;i++)
{
Array[i].SetCol(Col);
}
NRow = Row;
NCol = Col;
}
Dataset(Dataset<StorageType> &B)
{
NRow = B.GetNoOfRows();
NCol = B.GetNoOfCols();
if((Array = new Row[NRow]) == NULL){
cerr << "Martix::memory exhausted ... exiting" << endl;
exit(1);
}
register uInt32 i,j;
for(i = 0;i < NRow;i++)
{
Array[i].SetCol(NCol);
for(j = 0;j < NCol;j++)
{
Array[i][j] = B[i][j];
}
}
}
virtual ~Dataset()
{
delete[] Array;
}
Row &operator[](uInt32 Row){
return Array[Row];
}
uInt32 GetNoOfRows() const
{
return NRow;
}
uInt32 GetNoOfCols() const
{
return NCol;
}
Dataset<StorageType> operator*(Dataset<StorageType> const &B)
{
Dataset<StorageType> Temp(NRow,B.GetNoOfCols());
if(NCol == B.GetNoOfRows())
{
uInt32 Row = B.GetNoOfRows();
uInt32 Col = B.GetNoOfCols();
register uInt32 i, j, k;
register StorageType Product;
for(i = 0;i < NRow;i++)
{
for(j = 0;j < Col;j++)
{
Product = 0;
for(k = 0;k < Row;k++)
{
Product += Array[i][k]*B[k][j]; **--> error here**
}
Temp[i][j] = Product;
}
}
}
else
{
cerr << "Dataset::matrices aren't compatible for multiplication" << endl;
}
return (Temp);
}
void operator=(Dataset<StorageType> const &B)
{
register uInt32 i, j;
uInt32 Row = B.GetNoOfRows();
uInt32 Col = B.GetNoOfCols();
for(i = 0;i < Row;i++)
{
for(j = 0;j < Col;j++)
{
Array[i][j] = B[i][j]; **--> error here**
}
}
}
};
I am getting the following error
passing 'const Dataset' as 'this' argument discards qualifiers[-fpermissive]
at the places marked --> error here. . I need to multiply two Dataset from a caller class, using operator*, and making the argument const is mandatory. How do I resolve it? Some code example will be helpful.