let's say I have the following :
class A {
B b;
C c;
};
//....
A array[20];
Now I want to have access to the "b" member of class A, as if it was in an array.
Is there a C/C++ way to do this ? For instance with the knowledge of just the pointer to array and the size (20), I would like to be able to enumerate only the "b" members, like new_array[i]
. Is there a way to do this without directly referencing the class A ?
edit : reason I want to do this : I have a library which is storing this A array, and I'd like to only expose the class B (not A) to the users of the lib. I'd also like for the users of the library to iterate through the "b" members of "array", without having them know that it's actually a "b" member of a class A.