[問題] 關於把function寫進陣列裡面

看板C_and_CPP作者 (HenryLiKing)時間9年前 (2016/06/02 22:06), 9年前編輯推噓4(404)
留言8則, 5人參與, 最新討論串1/1
開發平台(Platform): (Ex: VC++, GCC, Linux, ...) Visual studio 2013 額外使用到的函數庫(Library Used): (Ex: OpenGL, ...) 問題(Question): 我想要把account 裡面的函式放到一個陣列裡面 但是我在Account外面的函式裡面這樣寫 void(*functions[5])(string) = { newAC->setEmail, newAC->setPassword, newAC->setName, newAC->setAddress, newAC->setPhone }; 會出現底下的錯誤 error C2440: 'initializing' : cannot convert from 'overloaded-function' to 'void (__cdecl *)(std::string)' 我一直搞不懂到底錯在哪裡? 拜託各位替我解答了! 錯誤訊息: 餵入的資料(Input): 預期的正確結果(Expected Output): 錯誤結果(Wrong Output): 程式碼(Code):(請善用置底文網頁, 記得排版) 補充說明(Supplement): 如果有錯誤或是違規的地方告知後必定立馬改善! -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 114.43.59.162 ※ 文章網址: https://www.ptt.cc/bbs/C_and_CPP/M.1464876396.A.2AB.html ※ 編輯: HenryLiKing (114.43.59.162), 06/02/2016 22:07:33

06/02 22:08, , 1F
大寫 'E' 修改標題 , 大寫 'T' 修改內文 .
06/02 22:08, 1F

06/02 22:08, , 2F
先把標題補上。
06/02 22:08, 2F

06/02 22:10, , 3F
請補上標題先
06/02 22:10, 3F
※ 編輯: HenryLiKing (114.43.59.162), 06/02/2016 22:11:48 抱歉 我已經改好了! ※ 編輯: HenryLiKing (114.43.59.162), 06/02/2016 22:12:26

06/02 22:53, , 4F
member function pointer 不是 function pointer
06/02 22:53, 4F

06/02 22:54, , 5F
你的需求,要用std::function加上std::bind
06/02 22:54, 5F

06/02 23:16, , 6F
根據樓上的提示:http://ideone.com/7DiiCg
06/02 23:16, 6F

06/02 23:20, , 7F
大概不是你想要的:http://ideone.com/Bogh7W XD
06/02 23:20, 7F

06/03 00:52, , 8F
文章代碼(AID): #1NK3riAh (C_and_CPP)