// generics/InstantiateGenericType.cpp // (c)2016 MindView LLC: see Copyright.txt // We make no guarantees that this code is fit for any purpose. // Visit http://mindviewinc.com/Books/OnJava/ for more book information. // C++, not Java! template 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 fb; Foo fi; // ... and it works with primitives }