This is the summary of the code, and it is supposed to be like that: There are 4 classes. The first one is an abstract class. It has two virtual functions(get & set method) that are redefined by the next two classes - both inherit the first one. The fourth class has an integer for dimension, and a matrix(size nxn) whose type is the first class. It also contains a destructor, get method and a destructor.
class Polje{
protected:
int value;
public:
virtual int GetValue() = 0;
virtual void SetValue(int n) = 0;
};
class Voda : public Polje{
int GetValue(){return value*2;}
void SetValue(int n){value = n;}
};
class Zemlja : public Polje{
int GetValue(){return value*(-3);}
void SetValue(int n){value = n+1;}
};
class Tabla{
public:
int dim;
Polje ***mat;
public:
int GetDim(){return dim;}
Tabla(int d){
dim = d;
mat = new Polje**[dim];
for(int i = 0; i < dim; i++)
mat[i] = new Polje*[dim];
}
Polje* GetPolje(int x, int y){
return mat[x][y];
}
~Tabla(){
for(int i=0; i<dim; i++)
delete [] mat[i];
delete [] mat;
}
};
I need to overload the += operator(argument Polje *p) in a way that it sets a new value to the element of the matrix, in the first free place. Also, is there a way to later determine what type of Polje(Voda or Zemlja) is the element of the matrix?