31 lines
521 B
C++
31 lines
521 B
C++
// generics/DogsAndRobots.cpp
|
|
// (c)2016 MindView LLC: see Copyright.txt
|
|
// We make no guarantees that this code is fit for any purpose.
|
|
// Visit http://mindviewinc.com/Books/OnJava/ for more book information.
|
|
|
|
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);
|
|
}
|