Ali*_*ğuz 5 c c++ function-pointers input function
我有一个具有函数指针输入的函数.我可以轻松地将函数名称作为输入.但我想知道是否可以将函数定义为输入.例如,我有这样的功能;
void exampleFunction ( void (*functionPointer)( void ) ) {
  codes
  ...
}
我可以在括号内输入这样的输入吗?例如;
exampleFunction( void helloFunction ( void ) {
  printf("Hello");
} );
它给出了像这样的编译错误,但有没有其他方法可以做到这一点?
这在C中是不可能的.
在C++中,您可以使用lambda表达式:
exampleFunction([](){ std::cout << "Hello"; });