#include #include #include "obj.h" using namespace std; //T must be a class with public members x, y, z that are names of data types. //T::x and T::z must have default constructors. //Warning: i will be uninitialized if T::x is built-in, pointer, or enumeration. template void f() { //Declare a local variable named i of data type T::x. typename T::x(i); //Declare a local variable named p of data type "pointer to T::y". typename T::y *p; //Declare a local variable named z1 of data type T::z. typename T::z z1 = typename T::z(); //Declare a local variable named r of data type "reference to T::z". typename T::z& r = z1; //Use the local variables i, p, r that we just defined. cout << &i << " " << &p << " " << &r << "\n"; } class myclass { public: typedef obj x; typedef int y; typedef int z; }; int main() { f(); return EXIT_SUCCESS; }