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

19 lines
357 B
C++

//: generics/InstantiateGenericType.cpp
// ©2015 MindView LLC: see Copyright.txt
// C++, not Java!
template<class T> class Foo {
T x; // Create a field of type T
T* y; // Pointer to T
public:
// Initialize the pointer:
Foo() { y = new T(); }
};
class Bar {};
int main() {
Foo<Bar> fb;
Foo<int> fi; // ... and it works with primitives
} ///:~