Why aren't these function signatures handled the same way?

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); // Works 
        funcVec.push_back(function);    // Works

        auto lambdaFunc = []() { std::cout << "Hi\n"; };

        funcPtrVec.push_back(lambdaFunc);   // Works
        funcVec.push_back(lambdaFunc);      // Doesn't work

    }

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;  // Works

    funcTakingFuncPtr(lambdaFunc);  // Works
    funcTakingFuncPtr(funcPtr);     // Works
    funcTakingFunc(lambdaFunc);     // Works
    funcTakingFunc(funcPtr);        // Works
    // They all work
}

, , - . , , , , ? , .

+6

All Articles