Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/154.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
什么是';字符(&;)[13]&x27;什么意思? 作为一个老C++程序员,我最近在学习C++ 11。当阅读有效的现代C++时,我发现了有趣的类型: char (&) [13]_C++_C++11 - Fatal编程技术网

什么是';字符(&;)[13]&x27;什么意思? 作为一个老C++程序员,我最近在学习C++ 11。当阅读有效的现代C++时,我发现了有趣的类型: char (&) [13]

什么是';字符(&;)[13]&x27;什么意思? 作为一个老C++程序员,我最近在学习C++ 11。当阅读有效的现代C++时,我发现了有趣的类型: char (&) [13],c++,c++11,C++,C++11,将数组传递给需要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"; funcTempla

将数组传递给需要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);
}

我从来没见过。这是什么意思?

如果我们插入丢失的函数参数名称,它将变成:

char (&param) [13]
毫无疑问,你对这一点很熟悉:

char param[13]

这当然是一个13个字符的数组。添加
&
意味着它是对相同代码的引用。之所以需要括号,是因为它是对数组的引用,而不是对引用数组的引用。

它是对十三个字符数组的引用。char。我想这可能意味着对字符[13]数组的引用,但为什么要用括号呢?谢谢@Peter,似乎我不能直接将它用作char(&)[13]=szhhello;会有编译错误;括号是因为C++语法怪异,需要在中间变量名> char(& sZJTY)[13 ] = SZRelo;编码>并用螺旋尺读取。实际上,使用C++11可以以更可读的方式编写它,比如
ref sz_text=szHello或(带自动类型扣除)
const auto&sz_text=szHello
。原因与
char*x[13]
是13个指针的数组,而
char(*x)[13]
是指向13个字符数组的指针相同。除了不可能有一个引用数组,所以
char&x[13]
不会编译。
char param[13]