[問題] 請教struct宣告問題
看板C_and_CPP (C/C++)作者youneverknow (睡覺一直想)時間12年前 (2013/10/07 14:20)推噓0(0推 0噓 13→)留言13則, 5人參與討論串1/2 (看更多)
開發平台(Platform): Code Blocks
額外使用到的函數庫(Library Used): 無
問題(Question):
宣告 struct Card,當中的char陣列無法被拉到main使用
餵入的資料(Input):
預期的正確結果(Expected Output):
錯誤結果(Wrong Output):
\card13.cpp||In function 'int main()':|
\card13.cpp|15|error: expected primary-expression before ']' token|
\card13.cpp|16|error: expected primary-expression before ']' token|
||=== Build finished: 2 errors, 0 warnings (0 minutes, 0 seconds) ===|
程式碼(Code):(請善用置底文網頁, 記得排版)
http://ideone.com/YlhyBW
補充說明(Supplement):
新新手,正在學習中,請多包涵
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 111.67.51.40
※ 編輯: youneverknow 來自: 111.67.51.40 (10/07 14:22)
→
10/07 14:50, , 1F
10/07 14:50, 1F
我有試過,即便我在struct裡先宣告好,
還是會一樣報錯:
http://ideone.com/A1BP5b
※ 編輯: youneverknow 來自: 111.67.51.40 (10/07 15:00)
→
10/07 15:15, , 2F
10/07 15:15, 2F
→
10/07 15:17, , 3F
10/07 15:17, 3F
→
10/07 15:17, , 4F
10/07 15:17, 4F
→
10/07 15:18, , 5F
10/07 15:18, 5F
→
10/07 15:19, , 6F
10/07 15:19, 6F
剛與handsome大對話,
了解到應該是初始化問題,
但我進一步請教一下,
為什麼A可以過? B會compile error?
A:http://ideone.com/R5iTqd
B:http://ideone.com/ZxfVlh
※ 編輯: youneverknow 來自: 111.67.51.40 (10/07 15:43)
→
10/07 15:49, , 7F
10/07 15:49, 7F
我還在建立對陣列、結構的正確觀念,
問些笨問題請多包涵:
在我的理解裡,A、B都是宣告一個結構deck,
然後對deck裡的三個變數初始化,
我不懂為什麼B這樣初始化會錯誤。
※ 編輯: youneverknow 來自: 111.67.51.40 (10/07 15:55)
→
10/07 16:02, , 8F
10/07 16:02, 8F
還請指點!
※ 編輯: youneverknow 來自: 111.67.51.40 (10/07 16:06)
→
10/07 16:12, , 9F
10/07 16:12, 9F
→
10/07 16:13, , 10F
10/07 16:13, 10F
→
10/07 16:14, , 11F
10/07 16:14, 11F
→
10/07 16:15, , 12F
10/07 16:15, 12F
→
10/07 16:16, , 13F
10/07 16:16, 13F
我大概懂了,
A是初始化,B是指定,即使Line 12那樣可以過,那也是指定,不是初始化,
而字串是不能這樣直接被指定給陣列,
是這樣嗎?
※ 編輯: youneverknow 來自: 111.67.51.40 (10/07 16:31)
討論串 (同標題文章)
C_and_CPP 近期熱門文章
PTT數位生活區 即時熱門文章