OnJava8-Examples/generics/DogsAndRobots.cpp
2015-09-07 11:44:36 -06:00

29 lines
382 B
C++

// generics/DogsAndRobots.cpp
// ©2015 MindView LLC: see Copyright.txt
class Dog {
public:
void speak() {}
void sit() {}
void reproduce() {}
};
class Robot {
public:
void speak() {}
void sit() {}
void oilChange() {
};
template<class T> void perform(T anything) {
anything.speak();
anything.sit();
}
int main() {
Dog d;
Robot r;
perform(d);
perform(r);
}