OnJava8-Examples/generics/Templates.cpp
Bruce Eckel 49edcc8b17 reorg
2015-06-15 17:47:35 -07:00

25 lines
421 B
C++

//: generics/Templates.cpp
// ©2015 MindView LLC: see Copyright.txt
#include <iostream>
using namespace std;
template<class T> class Manipulator {
T obj;
public:
Manipulator(T x) { obj = x; }
void manipulate() { obj.f(); }
};
class HasF {
public:
void f() { cout << "HasF::f()" << endl; }
};
int main() {
HasF hf;
Manipulator<HasF> manipulator(hf);
manipulator.manipulate();
} /* Output:
HasF::f()
///:~