Array of pointers to data members

111 views Asked by At
class A 
{
    float m_Period; // a1
    float m_Scale;  // a2
};

I can have pointer to a data member like this:

float A::*pFloat;

For reason of handle members in cycle i need an array of such pointers. How to do this.

2

There are 2 answers

0
James Kanze On BEST ANSWER

Either std::vector<float A::*> pFloats; or, if you need static initialization with the compiler counting the number of initializers, float A::*pFloat[] = {...};.

3
Steve Jessop On
typedef float A::*member_t;

Now you can declare an array or vector of member_t.