Created
April 8, 2016 19:17
-
-
Save mralexgray/6f436a0ff7599c6e5d46bd136c41ccd1 to your computer and use it in GitHub Desktop.
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
#include <inttypes.h> | |
#include <stdio.h> // for size_t | |
class Outputter; | |
class Printable { public: | |
virtual void printTo(Outputter &stream) const = 0; | |
}; | |
class Outputter { public: | |
Outputter() {} | |
void printout(const char* c) { printf("%s", c); } | |
void printout(const Printable& p) { p.printTo(*this); } | |
}; | |
Outputter log; | |
class Printer : public Printable { public: | |
Printer(){} | |
virtual void printTo(Outputter& pt) const { | |
return pt.printout("I am a printer"); | |
} | |
void print() { /* log.printout(*this); */ } | |
}; | |
Printer pp; | |
using namespace std; | |
int main(int argc, char *argv[]) { | |
log.printout(pp); | |
pp.print(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment