I have to misunderstand something because I thought that both cases are the same:
#include <iostream>
void function() { std::cout << "Hi\n"; }
int main()
{
std::vector<void(*)()> funcPtrVec;
std::vector<void()> funcVec;
funcPtrVec.push_back(function);
funcVec.push_back(function);
auto lambdaFunc = []() { std::cout << "Hi\n"; };
funcPtrVec.push_back(lambdaFunc);
funcVec.push_back(lambdaFunc);
}
Now in both cases, my compiler says that the function signatures are the same, void function () and void lambdaFunc (). I really thought that when a lambda function does not capture anything, it behaves like a free function that the same signatures seem to support. In addition, I assume that I am even more confused due to the fact that in the following everything seems to be treated the same way, as if they fall on the same thing:
void function() { std::cout << "Hi\n"; }
void funcTakingFunc(void()) {}
void funcTakingFuncPtr(void(*)()) {}
int main()
{
auto lambdaFunc = []() { std::cout << "Hi\n"; };
void(*funcPtr)() = lambdaFunc;
funcTakingFuncPtr(lambdaFunc);
funcTakingFuncPtr(funcPtr);
funcTakingFunc(lambdaFunc);
funcTakingFunc(funcPtr);
}
, , - . , , , , ? , .