[問題] 無法對函數指標陣列中的元素做賦值

看板C_and_CPP作者 (......)時間12年前 (2013/03/19 16:03), 編輯推噓0(003)
留言3則, 3人參與, 最新討論串1/1
開發平台(Platform): (Ex: VC++, GCC, Linux, ...) 額外使用到的函數庫(Library Used): (Ex: OpenGL, ...) 問題(Question): int (*foo[10])(void*,int *,char); 這行宣告是一個函數指標陣列沒錯吧 但是如下寫會編譯錯 *(foo+1)=abc; 要怎麼改呢@@? 我照著整數指標陣列相同的方法去做不能= = 餵入的資料(Input): 預期的正確結果(Expected Output): 錯誤結果(Wrong Output): 程式碼(Code):(請善用置底文網頁, 記得排版) #include<iostream> //#include<string> using namespace std; enum{A_1,A_2,A_3}; int abc(void *,int *,char); int main(){ //int (*foo[10])(void*,int *,char); int **foo(void*,int *,char); //*(foo+1)=&abc; //int *ptr[10]; int **ptr; ptr=new int*[10]; int kk=190; int jj=90; *(ptr+1)=&kk; *(ptr)=&jj; cout<<**(ptr+1)<<endl; cout<<**ptr<<endl; system("pause"); return 0; } int abc(void *p,int *q,char r){ cout<<"test"<<endl; } 補充說明(Supplement): -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 111.246.201.23

03/19 17:01, , 1F
也許你應該讓 abc 回傳一個 int
03/19 17:01, 1F

03/19 22:36, , 2F
不行ㄟ
03/19 22:36, 2F

03/19 22:59, , 3F
03/19 22:59, 3F
文章代碼(AID): #1HI1kzDw (C_and_CPP)