Is it possible to somehow declare and assign a function to function pointer func in main() without having an actual function add()?
Current Code:
#include <iostream>
int add(int a, int b)
{
return a + b;
}
int main()
{
typedef int (*funcPtr)(int a, int b);
funcPtr func = &add;
std::cout << func(2,3) << std::endl;
}
Preferred Style: (if possible)
#include <iostream>
int main()
{
typedef int (*funcPtr)(int a, int b);
funcPtr func = (funcPtr){return a + b}; // is something like this possible?
std::cout << func(2,3) << std::endl;
}
Is there a way to assign a function to function pointer dynamically like my last code?
const auto func = [](const auto a, const auto b){ return a + b; };