動態struct的問題 |
答題得分者是:RaynorPao
|
a_mi
一般會員 ![]() ![]() 發表:43 回覆:43 積分:22 註冊:2003-12-07 發送簡訊給我 |
|
RaynorPao
版主 ![]() ![]() ![]() ![]() ![]() ![]() 發表:139 回覆:3622 積分:7025 註冊:2002-08-12 發送簡訊給我 |
引言: 宣告 struct TRectInfo{int x; int y; int W; int H;} *RectInfo; 使用 RectInfo = new TRectInfo RectInfo[i].x = 10; RectInfo[i].y = 20; RectInfo[i].W = 30; RectInfo[i].H = 40; 請問這樣對嗎? a_mi 你好: 請參考以下的做法 宣告 typedef struct _TRectInfo { int x; int y; int W; int H; } TRectInfo, *PTRectInfo; 使用 TRectInfo ri; ri.x = 10; ri.y = 20; ri.W = 30; ri.H = 40; 陣列 TRectInfo *pri=new TRectInfo[10]; for(int i=0; i<10; i++) { pri[i].x=i; pri[i].y=i; pri[i].W=i; pri[i].H=i; } for(int j=0; j<10; j++) { ShowMessage(IntToStr(pri[j].x)+","+IntToStr(pri[j].y)+","+ IntToStr(pri[j].W)+","+IntToStr(pri[j].H)); } delete [] pri;
------
-- 若您已經得到滿意的答覆,請適時結案!! -- -- 欲知前世因,今生受者是;欲知來世果,今生做者是 -- -- 一切有為法,如夢幻泡影,如露亦如電,應作如是觀 -- |
a_mi
一般會員 ![]() ![]() 發表:43 回覆:43 積分:22 註冊:2003-12-07 發送簡訊給我 |
引言:因為我的程式會對這個struct做大小的變更,請問包子大如果要Resize陣列的話 BCB要怎麼寫呢? (我只會Delphi用SetLenght) 謝謝 :)a_mi 你好: 請參考以下的做法 宣告 typedef struct _TRectInfo { int x; int y; int W; int H; } TRectInfo, *PTRectInfo; 使用 TRectInfo ri; ri.x = 10; ri.y = 20; ri.W = 30; ri.H = 40; 陣列 TRectInfo *pri=new TRectInfo[10]; for(int i=0; i<10; i++) { pri[i].x=i; pri[i].y=i; pri[i].W=i; pri[i].H=i; } for(int j=0; j<10; j++) { ShowMessage(IntToStr(pri[j].x)+","+IntToStr(pri[j].y)+","+ IntToStr(pri[j].W)+","+IntToStr(pri[j].H)); } delete [] pri; |
pwipwi
版主 ![]() ![]() ![]() ![]() ![]() 發表:68 回覆:629 積分:349 註冊:2004-04-08 發送簡訊給我 |
|
a_mi
一般會員 ![]() ![]() 發表:43 回覆:43 積分:22 註冊:2003-12-07 發送簡訊給我 |
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |