CHAPTER 9

image

The Opaque Type Principle

Template type names can be too complex for the user to use directly, as they may be verbose or they may require very complex syntax. So you should either publish a convenient typedef or allow users to ignore their type altogether.

Plain C is full of opaque types.

In C, a file stream is handled via a pointer to an unknown FILE structure that resides in system memory (the C runtime pre-allocates a small number of these structures). To retrieve the current position in an open file, you call fgetpos(FILE*, fpos_t), passing the file pointer and another opaque type that acts as a bookmark. You can’t know or modify ...

Get Advanced Metaprogramming in Classic C++ now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.