我傳遞一個函數指針到另一個功能,我希望它是默認初始化, 而這也正是我想,但是這給語法錯誤如何在c/C++中默認初始化函數指針?
void bar(int i) {}
void foo(void (*default_bar=bar)(int)) {
//
}
錯誤:
Invoking: GCC C++ Compiler
g++ -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"src/f_13.d" -MT"src/BinarySearchTree_13.d" -o "src/BinarySearchTree_13.o" "../src/f_13.cpp"
In file included from ../src/f_13.cpp:10:
../src/tree.h:51: error: expected `)' before '=' token
../src/tree.h:51: error: 'foo' declared as function returning a function
../src/tree.h:51: error: expected ';' before ')' token
../src/tree.h:60: error: expected `;' before 'void'
make: *** [src/f_13.o] Error 1
只是一個點,這個工作得很好:
void foo(void (*default_bar)(int)) {