我有一个Visual Studio 2008 C++ 03应用程序,我在其中向类Foo
提供策略FooTraits
。如何创建一个定义了固定值类型的策略模板
struct FooTraits
{
enum { FooVal = 1 };
};
template< typename traits >
class Foo
{
public:
typedef typename traits::FooVal foo_val; // errors on this line
void FooDo(UINT matrix[ foo_val ]) { /*...*/ };
};
typedef Foo<FooTraits> Foot;
int main(int argc, char* argv[])
{
Foot f;
UINT matrix[ Foot::foo_val ] = { /*...*/ };
f.FooDo(matrix);
return 0;
}
但是,我得到的所有的typedef
一个全系列的编译器错误:
error C2146: syntax error : missing ';' before identifier 'foo_val'
error C2838: 'FooVal' : illegal qualified name in member declaration
error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
什么是创建一个定义一个固定值策略的正确方法是什么?