OnJava8-Examples/staticchecking/DogsAndRobots.cpp
Bruce Eckel 88dbdbbbcb update
2015-05-18 23:05:30 -07:00

27 lines
387 B
C++

//: staticchecking/DogsAndRobots.cpp
#include <iostream>
using namespace std;
class Dog {
public:
void talk() { cout << "Arf!" << endl; }
void reproduce() {}
};
class Robot {
public:
void talk() { cout << "Click!" << endl; }
void oilChange() {}
};
template<class T> void speak(T speaker) {
speaker.talk();
}
int main() {
Dog d;
Robot r;
speak(d);
speak(r);
} ///:~