I’m coding a C++ function that accepts a string, an array and the size of the array. It looks like this:
bool funcname (string skey, string sArr[], int arrSz)
I want to pass several array data types, such as double, char, long int, etc. Is it right to use string as data type for the array? Or is there a general data type that I can use?
Thanks in advance.
Using a string in this way is bad imo. Amongst other things you are sending an array of strings. You’d be better off using a std::vector. You could then template the function as follows:
This way you can directly query the vector for the size and you can pass through a vector of ANY data types.
Also bear in mind that its far more efficient to send structures through as const references instead of having a “potential” copy of the structures.