news:5398296986cdd4ac493c3d7fff7caa11@localhost.talkaboutprogramming.com...
How do I do this?
I have my function:
int* calc_c2e(string it, entry ea[]) { // ..........
and in the end I want to return an integer array.
Help is much appreciated
Its impossible to return arrays in C or C++.
Your function is declared as returning a pointer. You can return a pointer
to dynamically allocated memory (which is not the same as an array, just
similar)
int* calc_c2e(string it, entry ea[])
{
...
int dynamic_memory = new int[how_many_ints];
...
return dynamic_memory;
}
But don't forget to delete[] the memory when you are done with it.
I see you are already using string, now is the time to investigate vector.
You will find it much easier than messing with dynamic memory
vector<int> calc_c2e(string it, entry ea[])
or since copying vectors might be inefficient, pass a reference to the
'returned' vector.