function(LPCTSTR fmt, ...)这个函数什么意思?
调用的时候直接是
Cstring str;
function(str);而str只是一个参数,定义的时候的...是一种什么用法?
如果没区别我直接function(LPCTSTR fmt)不就好了嘛
[解决办法]
...是变参数,也就是说如果使用这样的定义 参数的数目是可变的 而如果你使用你说的方法 那么如果希望传入多个参数的时候 就不行了
[解决办法]
If at least one parameter occurs in the parameter list, the list can end with a comma followed by three periods (, ...). This construction, called the “ellipsis notation,” indicates a variable number of arguments to the function. (See Calls with a Variable Number of Arguments for more information.) However, a call to the function must have at least as many arguments as there are parameters before the last comma.
Calls with a Variable Number of Arguments
A partial parameter list can be terminated by the ellipsis notation, a comma followed by three periods (, ...), to indicate that there may be more arguments passed to the function, but no more information is given about them. Type checking is not performed on such arguments. At least one parameter must precede the ellipsis notation and the ellipsis notation must be the last token in the parameter list. Without the ellipsis notation, the behavior of a function is undefined if it receives parameters in addition to those declared in the parameter list.
To call a function with a variable number of arguments, simply specify any number of arguments in the function call. An example is the printf function from the C run-time library. The function call must include one argument for each type name declared in the parameter list or the list of argument types.
All the arguments specified in the function call are placed on the stack unless the __fastcall calling convention is specified. The number of parameters declared for the function determines how many of the arguments are taken from the stack and assigned to the parameters. You are responsible for retrieving any additional arguments from the stack and for determining how many arguments are present. The STDARGS.H file contains ANSI-style macros for accessing arguments of functions which take a variable number of arguments. Also, the XENIX?- style macros in VARARGS.H are still supported.
This sample declaration is for a function that calls a variable number of arguments:
int average( int first, ...);
Microsoft Specific —>
To maintain compatibility with previous versions of Microsoft C, a Microsoft extension to the ANSI C standard allows a comma without trailing periods (,) at the end of the list of parameters to indicate a variable number of arguments. However, it is recommended that code be changed to incorporate the ellipsis notation.
END Microsoft Specific
[解决办法]
可变参数,类似于printf的声明
int printf(const char* restrict format,...);