constVec
is an array of 4 constant pointers to members of the Vector4<T>
class that are of type T
Note. Members are not constants; pointers themselves.
First, since they are constant pointers, you need to initialize them in the constructor: (I just noticed the static
classifier, so it must be initialized outside the class, but if it was not static, you need to do this in the initialization list.)
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; }; template<typename T> const typename Vector4<T>::vec Vector4<T>::constVec = {&Vector4::member1,&Vector4::member2,&Vector4::member3,&Vector4::member4}; int main() { Vector4<int> v; for(int i=0; i<4; i++) { (v.*Vector4<int>::constVec[i]) = 5; } return 0; }
source share