使用模版定义union的有关问题?
使用模版定义union的问题???
我想定义这样一个类型:
typedef union {
struct { float x,y,z,w;};
float v[4];
} vec4f;
这样就可以:
vec4f v4f;
v4f.x = ...;
v4f.v[1] = ...;
而且在vc2005下编译运行通过.
后来又需要一个vec4i(成员都为int型的), vec4b(bool型)...
我就定义了一个模版:
template <typename Type>
union v4{
struct { type x,y,z,w;};
type v[4]; //这里出问题了...郁闷
};
本来想之后
typedef union v4 <float> vec4f;
typedef union v4 <int> vec4i;
...
可总是错误
error C2040: 'vect <Type,i> ::v ' : 'Type [4] ' differs in levels of indirection from 'Type '
望各位老大指点小弟....
------解决方案--------------------
class , struct, union都可以是模板:)
我想定义这样一个类型:
typedef union {
struct { float x,y,z,w;};
float v[4];
} vec4f;
这样就可以:
vec4f v4f;
v4f.x = ...;
v4f.v[1] = ...;
而且在vc2005下编译运行通过.
后来又需要一个vec4i(成员都为int型的), vec4b(bool型)...
我就定义了一个模版:
template <typename Type>
union v4{
struct { type x,y,z,w;};
type v[4]; //这里出问题了...郁闷
};
本来想之后
typedef union v4 <float> vec4f;
typedef union v4 <int> vec4i;
...
可总是错误
error C2040: 'vect <Type,i> ::v ' : 'Type [4] ' differs in levels of indirection from 'Type '
望各位老大指点小弟....
------解决方案--------------------
class , struct, union都可以是模板:)