Returning an array of characters

Hi everyone!

I have a private data member that is an array of characters that stores a bunch of numbers (123456789). The data member name is listNum. I am writing a method in my class that takes no parameters and returns the listNum data member but I'm having problems because it is only returning the first character of the array. I realize that when I return the name of a character array that it converts the name into a pointer to the first element of the array, hence why I am getting only the first number. I don't know how to get it to return the entire array of characters though. I know how to output them by looping through the array and such, but not return.

How do I do this?

1
2
3
4
char Numberclass::getListNum()
{
return *listNum;
}


Thanks!
For those wondering, I had to do the following:

1
2
3
4
char* Numberclass:getListNum()
{
return listNum;
}
This does not return the array (i.e. a copy of the array), but a pointer to the first element, which would allow changing to original array.
Use std::string or std::vector<char> instead.
Topic archived. No new replies allowed.