Let us suggest I have a class called vec4. Its a template and could be uint8, float or int in most cases. Other cases are allowed but are less likely. The class looks like this:
template<class T>
class vec4 {
public:
vec4(){}
virtual ~vec4(){}
union {
struct {
T x,y,z,w;
};
struct {
T r,g,b,a;
};
};
};
This helps me think about a problem in different ways when writing code and allows me to do other cool things also and I rather enjoy the design pattern when ever applicable.
The problem is I would like to extend the class and add functions in the case it is a 32 bit float. That I can do. I would also like to extend the union for a further maths paradigm where the third members are T c,y,m,k.
I am finding it very difficult to find material on the subject. This code extends the template, allowing specialised functions however, I would also like to extend the union within.
template<>
class vec4<float> {
public:
vec4(){}
virtual ~vec4(){}
};
The following specialisation compiles but doesn't allow me to also access members as an x,y,z,w object though;
template<>
class vec4<float> {
public:
vec4(){
this->i=0;
this->j=0;
this->k=0;
this->l=0;
}
vec4(float a){
this->i = a;
this->j = a;
this->k = a;
this->l = a;
}
union {
struct {
float i,j,k,l;
};
};
};
I was able to add this line:
struct vec4<float>;
to the specialized template. It would compile until trying to access the x,y,z,w members;