タイマーイベントで以下のことをやりたいのですが方法がわかりません。
だれか方法を教えてください!
内容:
クラスのあるメンバに時間を足しこむ。
ただし、クラスの情報がポインタArrayになっており、そのクラスのポインタ先のメンバ
に足しこまなければならない状況です。
イメージ:
○:更新したいクラスメンバ
1、2、3はクラスポインタのアドレスと考えてください。
------------------------------
1 | | | | | | ○ |
------------------------------
2 | | | | | | |
------------------------------
3 | | | | | | ○ |
------------------------------
ポインタArrayというのはCPtrArrayでしょうか?
ということで以下に続きます.
class CItem : public CObject
{
public:
CItem() {
nCnt = 123;
}
int nCnt;
};
xxxx:xxxx() {
CPtrArray Ary;
Ary.Add(new CItem);
Ary.Add(new CItem);
CItem* pItem = reinterpret_cast<CItem*>(Ary.GetAt(0));
pItem->nCnt += 100;
pItem = reinterpret_cast<CItem*>(Ary.GetAt(1));
pItem->nCnt += 200;
なんて感じでアクセスできます.
単なるクラスの配列,またはクラスの配列を指すポインタなら
下記のような感じです
CItem aItem[10];
CItem* paItem = aItem;
aItem[3].nCnt++;
paItem[3].nCnt++;
(paItem + 3)->nCnt++;
クラスのポインタ配列なら下記のような感じです
CItem* apItem[10];
for (int n = 0; n < 10; n++) {
apItem[n] = new CItem;
}
apItem[3]->nCnt++;