Created
February 11, 2014 03:58
-
-
Save daxim/8929036 to your computer and use it in GitHub Desktop.
misc-farm
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 <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(); | |
} |
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
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