Pointer to an array of data members

Why is the line marked 'won't compile' an error?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
enum Country {USA, China, ..., Jamaica, FIRST_COUNTRY = USA, LAST_COUNTRY = Jamaica, NUM_COUNTRIES};
struct Crowd {
	int numAmericans;
	int numPeople[NUM_COUNTRIES];  // Generalizing the above
}
// ...

int main () {
const int numCrowds = 10;
Crowd crowd[numCrowds];
int Crowd::*num[NUM_COUNTRIES];
	for (int i = 0; i < numCrowds; i++)
	{
		num[USA] = &Crowd::numAmericans;  // This compiles
		for (int COUNTRY = FIRST_COUNTRY; COUNTRY <= LAST_COUNTRY; COUNTRY++)  // Attempting to generalize
		    num[COUNTRY] = &Crowd::numPeople[COUNTRY];  // Won't compile.  Why?
//...

          }
}


P.S. My entire program runs fine if I repeat num[USA] = &Crowd::numAmericans; for AAALLL the other countries. Just trying to do it with a for-loop instead.
Last edited on
&Crowd::numPeople is a member pointer, not an array of integers, so using the subscript operator on it doesn't make sense.
Topic archived. No new replies allowed.