OnJava8-Examples/generics/Templates.cpp
2015-09-07 11:44:36 -06:00

25 lines
414 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()