Chapter 24. Miscellaneous Topics

Variable length argument lists are referenced, but not completely explained earlier in the book, so they are discussed in this chapter. An example of resource sharing is also presented.

24.1

Functions with Variable-Length Argument Lists

542

24.2

Resource Sharing

543

Functions with Variable-Length Argument Lists

In C and in C++ it is possible to define functions that have parameter lists ending with an ellipsis (. . .). The ellipsis allows the number of parameters and their types to be specified by the caller. The usual example of such a function is from <stdio.h>.

int printf(char* formatstr, ...)

This flexible mechanism permits calls such as

printf("Eschew Obfuscation!\n"); printf("%d days hath %s\n", 30, "September");  ...

Get An Introduction to Design Patterns in C++ with Qt 4 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.