2013-08-07 134 views
0

我想f指向一個f_pointer_type數組。那麼我在這裏錯過了什麼?我得到一個錯誤'作爲賦值的左操作數所需的左值'。這是什麼意思 ?指向函數指針數組的指針

#include <stdio.h> 
typedef char* (*f_pointer_type)(); 
char * retHello() 
{ 
    return "hello"; 
} 
int main() 
{ 
    char (* (*f())[])(); //Declare f to be a pointer to an array of pointers to function that gets nothing and return a char. 
    f_pointer_type funcs[3]; //an array of pointers to function that gets nothing and returns a pointer to char 
    f = &funcs; //ERROR : lvalue required as left operand of assignment 
    return 0; 
} 
+1

的功能? f_pointer_type ** f; - –

+0

我猜f被解釋爲一些瘋狂的函數前向聲明。 –

回答

3

如果你看了關於clockwise/spiral rule你會看到,f實際上是返回一個指向指針數組功能回到char*功能。換句話說,它是一個函數原型而不是變量聲明。

嘗試此代替:

f_pointer_type (*f)[]; 
+0

非常感謝! – elhamura

1

函數指針數組寫爲char* (*f[])()。你有錯誤的括號。

儘管總是使用typedef當然更好,例如f_pointer_type funcs[3]示例。

1

您定義f作爲function pointer.f是指向你爲什麼不f中的變量定義使用的typedef誰擁有void paramsreturn char *