1

Ugly interview question: How would you declare an array of N pointers to functions returning pointers to functions returning pointers to characters in c++? Show it with and without typedef.

Let's say the functions take no params.

Is mine correct with typedef?

typedef char* (*f1)();
typedef f1 (*f2)();

f2 a[N];
4
  • 6
    trick question. I wouldn't. Commented Nov 19, 2012 at 2:02
  • 3
    std::array<std::function<std::function<char*()>*()>*, N> :) Commented Nov 19, 2012 at 2:05
  • char *(*(*name_of_array[N])())() Commented Nov 19, 2012 at 2:12
  • 1
    id<id<char*()>*()>*[N] Commented Nov 19, 2012 at 2:14

2 Answers 2

1

typedef char *(*(*foo[])())();

But I definitely agree with @Xploit here. Don't ever write this.

Sign up to request clarification or add additional context in comments.

Comments

0

Function returning pointer to characters:

typedef char * (*fpc)(void);

Function returning pointer to function returning pointer to characters:

typedef fpc (*fpa)(void);

Array of function pointers to functions returning pointer to function return pointer to characters:

fpa my_array[N];

I'll leave the non-typedef version to the OP. There should be no reason to banish typedefs.

1 Comment

didnt you just repeat the question? he is just asking if he is right.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.