Skip to Content
Hands-On Design Patterns with C++
book

Hands-On Design Patterns with C++

by Fedor G. Pikus
January 2019
Intermediate to advanced
512 pages
14h 5m
English
Packt Publishing
Content preview from Hands-On Design Patterns with C++

Very old type erasure

The idea of writing a program without explicit type information is certainly not new. In fact, it predates object-oriented programming and the notion of objects by a long time. Consider this C program (no C++ here) as an example:

int less(const void* a, const int* b) {    return *(const int*)a - *(const int*)b;}int main() {    int a[10] = { 1, 10, 2, 9, 3, 8, 4, 7, 5, 0 };    qsort(a, sizeof(int), 10, less);}

Now remember the function declaration for qsort from the standard C library:

void qsort(void *base, size_t nmemb, size_t size,    int (*compar)(const void *, const void *));

Note that, while we are using it to sort an array of integers, the qsort function itself does not have any explicit types—it uses void* to pass in the ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Structural Design Patterns in Modern C++

Structural Design Patterns in Modern C++

Umar Lone

Publisher Resources

ISBN: 9781788832564Supplemental Content