My code contains three structures: struct ABC, struct DEF and struct GHI.
struct GHI contains the reference for ABC and DEF. Code also conains a for loop.
Within the for loop I want to access one reference during every iteration.
i.e. During iteration 1 : I want access reference to struct ABC
During iteration 2 : I want access reference to struct DEF.
Please suggest me how to achieve this.
Please have a look at the below code.
struct ABC
{
ABC()
{
}
int a;
int b;
};
struct DEF
{
DEF()
{
}
int c;
int d;
};
struct GHI
{
GHI()
{
}
ABC& A;
DEF& B;
};
void main()
{
GHI stghi;
for(int i =0; i < 2; i++)
{
// want to access one reference during every iteration.
}
You can't because the structures are different. The only way to do it would be to put an if statement in the loop (if i == 0, the access ABC, otherwise access DEF), but of course that's silly and defeats the entire point of the loop.
You can only do this if the structures are the same. From the looks of it, it looks like ABC and DEF could be the same because the members are the same, they just have different names.
So the question here is... why do you need DEF? Couldn't you just use 2 ABCs?