2

Suppose I want to declare an array of functions, and try the following

int (*funcs)(int, int)[10];

But turns out that the following declaration stands for an function returning an array, which does not compile.

How can I declare an array of functions properly?

2

2 Answers 2

4

Strictly speaking you may not declare an array of functions. You may declare an array of function pointers.

It seems you mean

int (*funcs[10])(int, int);

Another way is to introduce a using declaration (or a typedef declaration) like for example

using FP = int( * )( int, int );

FP funcs[10];

or

using FUNC = int ( int, int );

FUNC * funcs[10];
Sign up to request clarification or add additional context in comments.

2 Comments

The third option seems a little bit weird.
@KarenBaghdasaryan It has its own advantages because the same name FUNC you can using to declare a function and a function pointer..
1

It should be

int (*funcs[10])(int, int);

Or ask help of using (or typedef).

using fp = int (*) (int, int);
fp funcs[10];

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.