[問題] 請問struct裡的element可再動態宣告嗎?
請問struct裡的element可以再動態宣告嗎?
head檔===
class TForm1 : public TForm
{
__published: // IDE-managed Components
TButton *Button1;
void __fastcall Button1Click(TObject *Sender);
private: // User declarations
public: // User declarations
__fastcall TForm1(TComponent* Owner);
struct rainfall{
float *value;
};
rainfall *station;
};
cpp檔===
void __fastcall TForm1::Button1Click(TObject *Sender)
{
int num=100;
station = new rainfall[num];
//動態宣告station沒問題
for(int i=0; i<num; i++){
float *station[i].value = new float[num];
//上面這不行
//[C++ Error] Unit1.cpp(27): E2313 Constant expression required
//[C++ Error] Unit1.cpp(27): E2141 Declaration syntax error
}
}
請問有類似這樣的寫法嗎?
新手笨問題請多包涵
謝謝
※ 編輯: clough 來自: 140.115.61.78 (11/26 10:30)
推
11/26 10:41, , 1F
11/26 10:41, 1F
→
11/26 10:41, , 2F
11/26 10:41, 2F
→
11/26 10:42, , 3F
11/26 10:42, 3F
→
11/26 10:43, , 4F
11/26 10:43, 4F
→
11/26 10:59, , 5F
11/26 10:59, 5F
→
11/26 10:59, , 6F
11/26 10:59, 6F
推
11/26 11:06, , 7F
11/26 11:06, 7F
→
11/26 11:09, , 8F
11/26 11:09, 8F
C_and_CPP 近期熱門文章
PTT數位生活區 即時熱門文章