As part of my toilet reading on the C++ Standard ANSI ISO IEC 14882 2003, I came across the following:
14.3.1.2: A local type, a type with no linkage,
"Unnamed type" really means "unnamed enumeration or class type" [for more information, see the comments to this answer]. An enumeration or class type doesn't have to have a name. For example:
struct { int i; } x; // x is of a type with no name
You could try to use an unnamed type as a template argument through argument deduction:
template void f(T) { }
struct { int i; } x;
f(x); // would call f<[unnamed-type]>() and is invalid in C++03
Note that this restriction has been lifted in C++0x, so this will be valid (you'll also be able to use local types as type template parameters). In C++0x, you could also use decltype
to "name" an unnamed type:
template void g() { }
struct { int i; } x;
f(); // valid in C++0x (decltype doesn't exist in C++03)