I have several functions that return void. I made pointers to these functions and wanted to have an array of these functions:
Why does this code work:
#include <cstdio>
using std::puts;
void tell() {
puts("hi");
};
void slap() {
puts("goodbye");
}
int main(int argc, char *argv[])
{
void (*tp)() = tell;
void (*sp)() = slap;
void(*funcs[])() = {tp, sp};
for (auto point:funcs) {
point();
}
return 0;
}
When I try to execute this code without specifying a pointer in funcs(i.e. void(funcs[])() = {tp, sp};, I get " error: 'funcs' declared as array of functions of type 'void ()' "what exactly is what they are - so why is this an error?
I also don't get the syntax, doesn't that mean ()at the end it void(*funcs[])()points to a function call?
source
share