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