This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/////////////////////////////////////////////////////////////////////////////////////////////// | |
// Demonstrates a sort of pseudo-polymorphism in C using similar methods to the C++ compiler // | |
/////////////////////////////////////////////////////////////////////////////////////////////// | |
typedef struct vtable { // Virtual table for holding methods | |
int (*process)(int); // Pointer to a function that returns an int and takes in an int | |
} vtable; | |
typedef struct NumberProcessor { // "class" that processes an integer | |
const vtable* vtable; // Method table |