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 somet开发者_运维问答hing 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
.
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.
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.
E.g.
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
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++).
精彩评论