[英]What is the meaning of char (& test(…))[2]
What is the meaning of the following declaration: 以下声明的含义是什么:
char (& test(...))[2];
I pasted it inside a function body as is and it compiles all right. 我把它粘贴在一个函数体中,然后编译好了。 I don't know what I can do with it but it passes the compilation.
我不知道我能用它做什么,但它通过了编译。
I've encountered something similar in this answer. 我在这个答案中遇到过类似的东西。
It's the declaration of a function taking a variable argument list and returning a reference to an array of 2 char
. 它是一个函数的声明,它接受一个变量参数列表并返回一个2
char
数组的引用。
Note that if define a function like this the parameters are inaccessible (via standard means) as the <cstdarg>
macros require a variable argument list to follow a named parameter. 请注意,如果定义这样的函数,则参数是不可访问的(通过标准方法),因为
<cstdarg>
宏需要一个变量参数列表来跟随命名参数。
If you like, you can defined a function with this declaration and return a reference to suitable array. 如果您愿意,可以使用此声明定义一个函数,并返回对合适数组的引用。 You can call it with any parameters, subject to the restrictions for
...
parameters which include the restrictions that passing non-POD class types causes undefined behaviour. 您可以使用任何参数调用它,但受
...
参数的限制,其中包括传递非POD类类型导致未定义行为的限制。
Eg 例如
namespace
{
char samplearray[2];
}
char (& test(...))[2]
{
return samplearray;
}
Declare test as a vararg function returning a reference to an array of 2
char
s将测试声明为vararg函数,返回对2个
char
的数组的引用
A useful site for de-mangling such declarations is cdecl: C gibberish <-> English (although it doesn't understand varargs and is C oriented rather than C++). 一个用于解除此类声明的有用站点是cdecl:C gibberish < - >英语 (虽然它不理解varargs并且是面向C而不是C ++)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.