指標陣列宣告問題 |
|
IORIS
一般會員 發表:15 回覆:21 積分:7 註冊:2005-01-14 發送簡訊給我 |
假設今天我宣告一個全域變數的二維陣列temp[320][240]
想要改成二維指標陣列方式宣告 但會出現錯誤訊息 程式碼如下 [code] #include #pragma hdrstop #include "Unit1.h" #include <math.h><br />//--------------------------------------------------------------------------- #pragma package(smart_init) #pragma resource "*.dfm" TForm1 *Form1; float** temp1 = new float* [320]; for (int i=0; i<320; i ) temp1[i]= new float [240]; //--------------------------------------------------------------------------- __fastcall TForm1::TForm1(TComponent* Owner) : TForm(Owner) { } [/code] 會出現以下錯誤訊息 [C Error] Unit1.cpp(13): E2040 Declaration terminated incorrectly [C Error] Unit1.cpp(13): E2141 Declaration syntax error [C Error] Unit1.cpp(13): E2238 Multiple declaration for 'i' [C Error] Unit1.cpp(13): E2344 Earlier declaration of 'i' [C Error] Unit1.cpp(13): E2141 Declaration syntax error 感覺上是他不讓我執行for的指令 請問要怎樣宣告才能達到這個效果? 謝謝 |
dllee
站務副站長 發表:321 回覆:2519 積分:1711 註冊:2002-04-15 發送簡訊給我 |
你在函式的外面寫了程式,自然是無法 compile 過的,如下,
把宣告與程式分開就可以了。 float** temp1; //--------------------------------------------------------------------------- __fastcall TForm1::TForm1(TComponent* Owner) : TForm(Owner) { temp1 = new float* [320]; for (int i=0; i<320; i ) temp1[i]= new float [240]; }
------
http://www.ViewMove.com |
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |