I know how to calculate the length for a string array in c++ (sizeof(arr)/sizeof(arr[0])
), but I'm having a problem calculating the length of a string array if I pass an array through a method that's inside another class. Is there a reason why this happens?.
main.cpp
/* Allways returns 3 */
std::string arr[3];
int length = sizeof(arr)/sizeof(arr[0]);
std::cout << length << std::endl;
main.cpp but calling the method from a class
/* Allways returns 0 */
Test* test = new Test();
std::string arr[3];
test->length(arr);
Test.cpp
void Test::length(std::string arr[]){
int length = sizeof(arr)/sizeof(arr[0]);
std::cout << length << std::endl;
}
I have passed in the array as a reference but It's not letting me do that, I have tried converting the array into a char array and passing in the value.