0

私の主なプログラムは、乱数を生成して 2 次元配列でオブジェクトの動きを作成し、それを追跡することです。

私の関数の 1 つはvoid current_row(int row){position = row};、オブジェクトの現在の行を追跡します。

変数はグローバルではないためです。現在の場所を呼び出して次の動きに更新する問題を見つけています。これは、他の関数がどのように見えるかです:

void movement (){
    int row;
    row = current_row();
    /*
     * Here is the problem i'm having. This may well be 
     * a third function which has the same information 
     * as my first function. But still how do I access
     * once without modifying it and access it  
     * again to update it?
     */

    // call another function that creates new row.
    // update that info to the row
}

私はc ++が初めてです。

4

2 に答える 2

1

インスタンス変数を使用して追跡します。そのため、インスタンス変数が存在します。関数呼び出し間で値を保持するためです。

于 2013-09-07T14:10:45.617 に答える