TITLE: templates: recovering a type from a pointer type PROBLEM: adamnash@cs.stanford.edu (Adam Nash) [...] for semantic reasons, the template assumes that DATA is a pointer type. [...] template void GIDTable::ReadFromStream(LStream *inStream) { DATA data; ... data = new DATA; (*data).ReadFromStream(inStream); ... } The problem occurs on the second line. data is of type DATA, so you really want to allocate a new (*DATA). IE, if DATA is a CBar *, then data is a CBar *, so we want it to say: data = new CBar; How can I do this, only knowing the pointer type? RESPONSE: fjh@mundook.cs.mu.OZ.AU (Fergus Henderson), 15 Mar 96 You can use a partial template specialization: template struct dereference {}; template struct dereference { typedef T type; }; Then just write data = new dereference::type; (I note in passing that this would of course be less obfuscated if C++ supported template typedefs...) Now, the reason that all of this belongs in comp.std.c++ not comp.lang.c++ is that the above code is valid according to the standard, but is highly unlikely to work with your favourite C++ compiler. Partial specialization is a relatively new feature, and few C++ compilers support it yet.