How it works...

Type erasure (or type erasing) is simply the act of removing, hiding, or reducing type information about an object, function, and so on. In the C language, type erasure is used all the time. Check out this example:

int array[10];memset(array, 0, sizeof(array));

In the preceding example, we create an array of 10 elements, and then we use the memset() function to clear the array to all zeros. The memset() function in C looks something like this:

void *memset(void *ptr, int value, size_t num){    size_t i;    for (i = 0; i < num; i++) {        ((char *)ptr)[i] = value;        }    return ptr;}

As shown in the preceding code snippet, the first parameter the memset() function takes is void*. The array in our preceding example, however, is an array of ...

Get Advanced C++ Programming Cookbook 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.