Comma omitted in variadic function declaration in C++

后端 未结 4 1110
余生分开走
余生分开走 2021-02-05 00:14

I am used to declaring variadic functions like this:

int f(int n, ...);

When reading The C++ Programming Language I found that the dec

4条回答
  •  难免孤独
    2021-02-05 01:08

    Currently, both of these declarations have the same meaning:

    int f(int n, ...);
    int f(int n ...);
    

    This leads to an issue where the following two declarations are both legal, yet have wildly different meanings:

    template  void f(T...); // function template with parameter pack
    template  void f(T...);    // variadic function
    

    Once C++11 introduced variadic templates, it is much more likely that the second declaration is a programmer error rather than lazily omitting the comma. As a result, there was a proposal to remove the latter from the language (P0281), but it was apparently rejected.

提交回复
热议问题