省略号作为任何可变参数模板之外的构造函数参数

Hol*_*Cat 3 c++

请考虑以下代码:

#include <iostream>

struct S
{
    S(const char *p) { std::cout << '[' << p << ']'; }
};

int main()
{
    S var(...); // <------
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

它在GCC 5.2上编译好-pedantic -pedantic-errors,但没有打印.我不知道这个语法意味着什么,我无法找到任何有关它的信息.

看起来它只是阻止了一个对象的构建,但我从来没有听说过这样的功能.

问题是:当用作构造函数参数时,省略号的含义什么?

Mik*_*CAT 10

它应该是具有可变长度参数的函数原型.

为了确保它,我添加两行并得到未定义的引用错误.

#include <iostream>

struct S
{
    S(const char *p) {std::cout << '[' << p << ']';}
};

int main()
{
    S var(...); // <------ function prototype declaration
    var(); // attempt to call the declared function, which is not defined
    var(1); // the same as above
    return 0;
}
Run Code Online (Sandbox Code Playgroud)