How to declare function returning array of Integer pointers

C

Clark S. Cox III

How can I declare function returning array of Integer pointers . Please
help !!

You can't. You can, however, declare a function returning any of:
A reference to an array
A pointer to an array
A vector
A structure containing an array,
etc.

You could also write a function that takes as a parameter a reference
or pointer to any of the above, and then populates the
referenced/pointed-to object instead of returning the same data.

Another option is to write a function that takes an output iterator as
a parameter. The function could then write to that iterator.

Which of these you should use depends on the actual problem that you're
trying to solve.
 
D

Dumaiu

As has been pointed out, if you're working with C arrays you need to
be more specific about what you're trying to do in order to get a clear
answer. You don't have to return anything if the array already
exists--just pass it into the function. If the function creates it,
it'll have to allocate it on the heap and return a pointer.
std::vector<int*> would almost always be recommended unless you were
newly trying to learn the language. (After all, this isn't comp.lang.c
;-)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,048
Latest member
verona

Latest Threads

Top