开发者

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 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 chars

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++).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜