I have been trying to pass an array to another function with the hopes of iterating through it based on size to no avail.. Here's what I have been attempting and what the output is:
void check_array(std::string str_arr[])
{
// print statistics
std::cout << "# of bytes in object: " << sizeof(str_arr) << std::endl;
std::cout << "# of bytes in element: " << sizeof(str_arr[0]) <<std::endl;
std::cout << "Object address: " << &str_arr << std::endl;
}
int main()
{
// initalize stuff
std::string str_arr[2];
str_arr[0] = "First element";
str_arr[1] = "Second element";
// print statistics
std::cout << "# of bytes in object: " << sizeof(str_arr) << std::endl;
std::cout << "# of bytes in element: " << sizeof(str_arr[0]) <<std::endl;
std::cout << "Object address: " << &str_arr << std::endl;
// pass it on so the other method can see
check_array(str_arr);
}
The output is:
"# of bytes in object: 16" "# of bytes in element: 8" "Object address "
"# of bytes in object: 8" "# of bytes in object: 8" "Object address "
How do I pass this array to a function and get the same numbers for 'bytes in object' and more importantly, the same address? I've tired passing by reference like I would with a normal pod type but I get compile errors..
Thanks!