0

C++ 20

I have this function:

int (*funcArrayReturn())[6];

The function returns a pointer to an array int[6] (6 elements aggregated).

And I need a pointer of pointers of n elements(in this case 3) dynamically allocated like this:

int (*(*(*funcPtr2)[3])())[6];

C++ 20

int (*funcArrayReturn())[6]
{
    int x[6];

    int (*array_matrix_allocated)[6] = new int[1][6]{ 25 };

    int number = array_matrix_allocated[0][0];
    
    number = array_matrix_allocated[0][2];

    return array_matrix_allocated;
}

I would dynamically allocate the pointer of this function with n elements

Pointer of pointers of 3 elements of functions with a return of a pointer of array int of n elements (6 in this case)

int (*(*(*funcPtr2)[3])())[6]` = new (int (*(*[10])[3]())[6]);)

(this is a wrong expression(10 elements)

Thank you

2
  • A pointer-to-function can't be dynamically allocated. Array types are not valid as a return type. Do you mean a function that returns a (pointer to a) dynamically allocated array? Commented Nov 28, 2024 at 9:08
  • Could you please state what your program is supposed to do, rather than what your attempt looks like now? Commented Dec 22, 2024 at 0:20

0

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.