OnJava8-Examples/generics/DogsAndRobots.cpp
2015-04-20 15:36:01 -07:00

28 lines
348 B
C++

//: generics/DogsAndRobots.cpp
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);
} ///:~