OnJava8-Examples/generics/DogsAndRobots.cpp

29 lines
389 B
C++
Raw Normal View History

2015-04-20 15:36:01 -07:00
//: generics/DogsAndRobots.cpp
2015-05-29 14:18:51 -07:00
// <20>2015 MindView LLC: see Copyright.txt
2015-04-20 15:36:01 -07:00
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);
} ///:~