Quick C++ Question

Barnaby W. Füi

Elite Member
Aug 14, 2001
12,343
0
0
I don't think you can. You'd have to return a pointer, or perhaps a vector (but returning a big object by value like that is nasty). The ideal solution might be be a refcounted pointer, but that's getting into additional libraries and stuff. Actually I think an auto_ptr might be appropriate here (and it's standard C++), although they are sneaky and you really need to understand how they work to use them.

It would help to know more specifics on what this function does and how you use it.
 

dighn

Lifer
Aug 12, 2001
22,820
4
81
if you know the maximum size in advance, you can also pass it an array from the caller and have the function fill it out
 

Barnaby W. Füi

Elite Member
Aug 14, 2001
12,343
0
0
Originally posted by: Deeko
Return a pointer to the beginning of the array....same thing.

If the array is allocated in that function then it's important to remember that the caller needs to delete it when it's done. And watch out for exceptions! shared_ptr would be ideal.