Skip to content

Instantly share code, notes, and snippets.

View George-lewis's full-sized avatar
💭
He's Simple, He's Dumb, He's the Pilot

George Lewis George-lewis

💭
He's Simple, He's Dumb, He's the Pilot
  • Toronto, Canada
  • 02:27 (UTC -04:00)
View GitHub Profile
@George-lewis
George-lewis / polymorphism.c
Last active December 22, 2019 05:48
Virtual in C++
///////////////////////////////////////////////////////////////////////////////////////////////
// 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