Liu Yan Liu Yan - 3 years ago 158
C++ Question

What does 'char (&) [13]' mean?

As an old c++ programmer, I'm learning c++11 recently. When reading Effective Mordern C++, I found the interesting type:

char (&) [13]


When passing an array to a function template requiring T&:

template<typename T>
void funcTemplate1(T& param)
{
std::cout << boost::typeindex::type_id_with_cvr<T>().pretty_name() << std::endl;
}
void main()
{
char szHello[] = "Hello, World";
funcTemplate1(szHello);
}


It output :

char (&) [13]


Never have seen that. What does is mean?

Answer Source

If we insert the lost function parameter name, it becomes:

char (&param) [13]

You're undoubtedly familiar with this:

char param[13]

Which of course is an array of 13 characters. Adding the & means it is a reference to the same. The parentheses are needed because it is a reference to an array, not an array of references.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download