I need to give an array to a function. Different functions will give this function arrays of different sizes, so i decided to take a pointer.
Here is what i have so far:
My problem is that my size of the type array in fjncb is always 1 st makes thing something is wrong in the way i am trying to give the array to the gunction.
Based on the code you posted the first thing I see is in "funcA". You define an array of strings and fill the array, but this array has local scope to the function. When the function ends so does the array and anything that you have filled it with. Trying to pass this array to another function from anywhere other than "funcA" would mean that you have nothing to point to.
In "funcB":
Line 9. "String" is the wrong way to refer to the type. It is either "std::string" or "string" all lower case letters.
Line 11. Not sure what is around the string, but it will not work. Whatever that character is it is not the double quote that is needed.
Line 12. Best not to use a C function on a C++ string. Also this use of sizeof is written wrong. Using the string class you have access to ember functions ".size()" and ".length()" which will tell you how many characters are in the string. I think what you may want here is std::size_t size = type[index].size;. Where "std::size_t" is another name for unsigned int which is what the .size()" function returns.
If the point is to determine how many elements in the array it is better to pass a variable for the size of the array to the function. And there is an easy way to do that. Since you have only posted part of your code it will take me a bit to work up an example.
Both styles are the same. The second example will degrade to a pointer if used. Either way both access the array in the same way with a subscript. And I do not believe the is any advantage in one or the other.
Line 12. Best not to use a C function on a C++ string. Also this use of sizeof is written wrong. Using the string class you have access to ember functions ".size()" and ".length()" which will tell you how many characters are in the string. I think what you may want here is std::size_t size = type[index].size;. Where "std::size_t" is another name for unsigned int which is what the .size()" function returns.
Yes the use of sizeof is incorrect in this content, but remember the type is a pointer to a String (whatever String is). A pointer has a specific implementation defined size and that is what sizeof will return for "type" in this instance.
Also size_t is an implementation defined unsigned type, usually either unsigned long or unsigned int (at the present time for most desktop implementations). However it could be any unsigned type.
Also size_t is an implementation defined unsigned type, usually either unsigned long or unsigned int (at the present time for most desktop implementations). However it could be any unsigned type.
Thank you. It looks like somewhere I came to the wrong idea.