Home > Uncategorized > typename

typename

Lately I’ve been migrating lots of code developed with earlier versions of Visual Studio to the latest, 2008. One situation that keeps arising, now that MSVC is more standards compliant, is the requirement to use typename when defining and using templates.

Error messages can be somewhat misleading:

Error 6 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int c:...myapp.h 59 myapp

when the compiler sees:

static instances_list::size_type size(void) { return s_instances.size();}

easily fixed as:

static typename instances_list::size_type size(void) { return s_instances.size(); }

From the Visual Studio docs:

“This keyword must be used if the name is a qualified name dependent on a template argument; it is optional if the qualified name is not dependent. For more information, see Templates and Name Resolution. ”

I expect typename was introduced to simplify compiler implementation and, while this worked in earlier versions of MSVC, this was likely due to Microsoft’s engineers putting in a lot of hard work.

Categories: Uncategorized Tags:
  1. No comments yet.
  1. No trackbacks yet.