I am trying to access the outer class variable cell[i][j]
from the inner class method iterateForward
.
I do not want to pass this
of outer class to iterateForward
as iterateForward(Matrix&)
, since it will add a parameter to iterateForward.
Inner class Method:
Pos Matrix::DynamicCellIterator::iterateForward(){
....................
(Example) outerRef.cell[i][j].isDynamic = true;
.....................
}
Here is my class:
class Matrix {
class DynamicCellIterator{
Cell* currentCellPtr;
Matrix& outerRef; //This will be the key by which i'll get access of outer class variables
public:
DynamicCellIterator(Matrix&);
Pos iterateForward();
};
Cell cell[9][9];
DynamicCellIterator dynIte(*this); // I have a problem of initializing the outerRef variable.
Error errmsg;
bool consistent;
public:
Matrix();
Matrix(Matrix&);
................
}
//Here I tried to initialize the outerRef.
Matrix::DynamicCellIterator::DynamicCellIterator(Matrix& ref){
this->currentCellPtr = NULL;
this->outerRef = ref;
}
How can I initialize outerRef
?