内部クラスメソッドiterateForward
から外部クラス変数cell[i][j]
にアクセスしようとしています。C++の内部クラスから外部クラスオブジェクトにアクセスする方法
外部クラスのthis
をiterateForward
にiterateForward(Matrix&)
として渡したくないのは、iterateForwardにパラメータを追加するためです。
内部クラスのメソッド:
Pos Matrix::DynamicCellIterator::iterateForward(){
....................
(Example) outerRef.cell[i][j].isDynamic = true;
.....................
}
にここでは、私のクラスである:
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;
}
にはどうすればouterRef
を初期化することができますか?
ないあなたが取得している何のエラーを確認しますが、私はマトリックス:: DynamicCellIterator :: DynamicCellIterator(行列とREF)を記述します:outerRef(REF)の{ –
可能な重複[内部クラスはプライベート変数にアクセスできますか?](http://stackoverflow.com/questions/486099/can-inner-classes-access-private-variables) –