It's an exercise of C++ Primer 5th. I don't know how to solve it?
The problem described as:
Write the declaration for a function that returns a reference to an array of ten strings, without using either a trailing return, decltype, or a type alias.
My codes:
#include <iostream>
#include <string>
std::string (&func(std::string a[])) [10]
{
return a;
}
int main()
{
std::string a[10];
std::string (&b)[10] = func(a);
for (const auto &c : b)
std::cout << c << std::endl;
return 0;
}
compile errors:
e6_36.cc:6:12: error: non-const lvalue reference to type 'std::string [10]' cannot bind to a value of unrelated type 'std::string *' (aka 'basic_string, allocator > *')
return a;
^
1 error generated.