david said:
Hi All,
I just want to write a function return char array,but I cant. I am not
good at C++ 's concept since I used to use Java before. Would you please
help me to fix that ? Thanks..
Arrays are not "First class citizens" in C++. They cannot be passed to a
function or returned from a function (not directly, anyway). You have a
few options.
1. You can return a pointer to an array.
2. You can return some kind of class object containing an array.
3. You can return a container, such as std::vector.
I'd recommend option 3.
Option 1 has a few gotchas, such as 1) you'd damn well better not return
a pointer to a local automatic array, 2) if you return a static array
you might have problems because a second call to the function will
modify the result from an earlier call, and 3) if you return a dynamic
array, the caller has to be sure to free that array.
Option 2 is not very elegant or flexible.
-Kevin