I tried this example from "C++ Template - The Complete Guide" by Nicolai M. Josuttis
#include <iostream>
using namespace std;
template< typename T >
class List {
};
typedef enum { RED, GREEN, BLUE } *color_ptr;
int main() {
struct Local {
int x;
};
List< Local > l; // error : local type in template argument
List< color_ptr > l1; // error : unamed type in template argument.
return 0;
}
With g++ under Ubuntu 9.04, I got compiler errors. However, this piece of code was compiled successfully in Visual C++ 2008. And as I read from the book : "Template type arguments are the "values" specified for template type parameters. Most commonly used types can be used as template arguments, but there are two exceptions: 1. Local classes and enumerations( in other words, types declared in a function definition ) cannot be involved in template type arguments. 2. Types that involve unnamed class types or unnamed enumeration types cannot be template type arguments ( unnamed classes or enumerations that are given a name through a typedef declaration are OK. ) So is there a mistake in Visual C++ ?