I came across this code and was wondering what it means.
But even after some 15 minutes of looking at it does not make sense to me.
template< typename T >
struct Vector4 {
typedef T Vector4<T>::* const vec[4];
static const vec constVec;
//just to have some member instances of T
T member1, member2, member3, member4;
};
So what is the type of constVec?
Please do not just repeat the typedef but explain in common language.
My notes so far:
- Why are there two types (
TandVector4<T>), is this a function pointer? - What does ::* mean? Take everything from the scope of Vector4?
- Is it a const pointer array? But why the :: then?
constVecis an array of 4 constant pointers to the members of theVector4<T>class which are of typeTNote: The members aren’t constant, the pointers themselves are.
First, since these are constant pointers, you need to initialize them in the constructor: (I’ve just noticed the
staticqualifier, so it has to be initialized outside the class, but if it weren’t static, you’d need to do that in the initialization list.)