[問題] 一個問題

看板Programming作者 (self)時間13年前 (2011/07/13 17:34), 編輯推噓0(003)
留言3則, 2人參與, 最新討論串1/1
struct account{ char *account; char *password; }; typedef struct account Account; typedef Account *AccountPtr; AccountPtr account[10]; account[0] = malloc(sizeof(Account)); 為何compile時它說"invalid conversion from `void*' to `Account*' "呢? 我知道用malloc會回傳void沒錯 但教科書裡這樣寫也可以過 而且這樣assign好像也是可以的? 謝謝 -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 140.112.241.190

07/13 17:37, , 1F
C語言可以過,C++必須要轉型
07/13 17:37, 1F

07/13 17:38, , 2F
account[0] = (AccountPtr)malloc(....);
07/13 17:38, 2F

07/13 23:28, , 3F
Oh, yes!! 感謝^^
07/13 23:28, 3F
文章代碼(AID): #1E7MQxfQ (Programming)