Question about a function definition (three dots in parameters..)

前端 未结 4 1975
生来不讨喜
生来不讨喜 2020-12-07 18:47

I came across a function definition:

char* abc(char *f, ...)
{
}

What do the three dots mean?

4条回答
  •  鱼传尺愫
    2020-12-07 19:02

    They are called an elipsis and they mean that the function can take an indeterminate number of parameters. Your function can probably be called like this:

    abc( "foo", 0 );
    abc( "foo", "bar", 0 );
    

    There needs to be a way of indicating the end of the list. This can be done by using the first parameter, as ion a printf(0 format string, or by a special terminator, zero in the example above.

    Functions with a variable number of parameters are considered bad form in C++, as no type checking or user defined conversions can be performed on the parameters.

提交回复
热议问题