全國最多中醫師線上諮詢網站-台灣中醫網
發文 回覆 瀏覽次數:798
推到 Plurk!
推到 Facebook!

動態struct的問題

答題得分者是:RaynorPao
a_mi
一般會員


發表:43
回覆:43
積分:22
註冊:2003-12-07

發送簡訊給我
#1 引用回覆 回覆 發表時間:2004-08-11 12:51:08 IP:61.218.xxx.xxx 未訂閱
宣告 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; 請問這樣對嗎?
RaynorPao
版主


發表:139
回覆:3622
積分:7025
註冊:2002-08-12

發送簡訊給我
#2 引用回覆 回覆 發表時間:2004-08-11 13:04:32 IP:203.73.xxx.xxx 未訂閱
引言: 宣告 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;    
-- Enjoy Researching & Developing -- 發表人 - RaynorPao 於 2004/08/11 13:19:13
------
-- 若您已經得到滿意的答覆,請適時結案!! --
-- 欲知前世因,今生受者是;欲知來世果,今生做者是 --
-- 一切有為法,如夢幻泡影,如露亦如電,應作如是觀 --
a_mi
一般會員


發表:43
回覆:43
積分:22
註冊:2003-12-07

發送簡訊給我
#3 引用回覆 回覆 發表時間:2004-08-11 13:43:37 IP:61.218.xxx.xxx 未訂閱
引言:
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;    
-- Enjoy Researching & Developing -- 發表人 - RaynorPao 於 2004/08/11 13:19:13
因為我的程式會對這個struct做大小的變更,請問包子大如果要Resize陣列的話 BCB要怎麼寫呢? (我只會Delphi用SetLenght) 謝謝 :)
pwipwi
版主


發表:68
回覆:629
積分:349
註冊:2004-04-08

發送簡訊給我
#4 引用回覆 回覆 發表時間:2004-08-11 14:30:06 IP:211.76.xxx.xxx 未訂閱
a_mi你好: 可以用vector來做到這個功能。  
#include 
using namespace std;    vector RectInfo;
RectInfo.resize(10);
RectInfo[2].x = 10;     
發表人 - pwipwi 於 2004/08/11 14:32:52
a_mi
一般會員


發表:43
回覆:43
積分:22
註冊:2003-12-07

發送簡訊給我
#5 引用回覆 回覆 發表時間:2004-08-11 15:36:48 IP:61.218.xxx.xxx 未訂閱
引言: a_mi你好: 可以用vector來做到這個功能。
#include 
using namespace std;    vector RectInfo;
RectInfo.resize(10);
RectInfo[2].x = 10;     
發表人 - pwipwi 於 2004/08/11 14:32:52
我試試...謝謝 :)
系統時間:2024-06-29 15:16:14
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!