我将一个函数指针传递给另一个函数,我希望它被默认初始化,这就是我正在尝试的,但这会产生语法错误
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)) {