Skip to content

Instantly share code, notes, and snippets.

@daxim
Created February 11, 2014 03:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save daxim/8929036 to your computer and use it in GitHub Desktop.
Save daxim/8929036 to your computer and use it in GitHub Desktop.
misc-farm
#include <iostream>
using namespace std;
class Animal {
public:
virtual string noise() = 0;
void speak() {
cout << this->noise() << endl;
}
};
template <class _> class Vehicle: public _ {
public:
void go() {
cout << "Brrrrm!" << endl;
}
};
class Hitchable {
public:
virtual void go() = 0;
void pull_plough() {
cout << "Hitching plough" << endl;
this->go();
}
};
class Tractor: public Vehicle<Hitchable> {
};
class Horse: public Animal, public Hitchable {
public:
string noise() {
return "Neigh!";
}
void go() {
cout << "Clip-clop" << endl;
}
};
int main() {
Tractor t;
t.pull_plough();
Horse h;
h.pull_plough();
}
CXXFLAGS = -fmessage-length=0 -g3 -O0 -pedantic -std=c++11 -Wall -Wextra
all: main.cpp
$(CXX) $(CXXFLAGS) -c -o main.o main.cpp
$(CXX) -o ./farm main.o
help:
@echo make CXX=clang++
@echo '# or just `make` for g++'
@echo ./farm
@echo make clean
clean:
rm -f *.o ./farm
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment