2015-04-20 15:36:01 -07:00
|
|
|
|
//: generics/Templates.cpp
|
2015-05-29 14:18:51 -07:00
|
|
|
|
// <20>2015 MindView LLC: see Copyright.txt
|
2015-04-20 15:36:01 -07:00
|
|
|
|
#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()
|
|
|
|
|
///:~
|