views:

67

answers:

1

Hi, i have some vars live:

int foo1;
int foo2;
..

and i want to reach them from:

for (int i = 1;i<=2;i++)
{
   // howto get foo1 and foo2?
}

how to get them?

EDIT, end what when it will be no int but a Opject *pointer;?

+6  A: 

You can't; you need an array of some kind. e.g.:

int foo[2];   /* Two elements, foo[0] and foo[1] */
for (int i = 0; i < 2; i++)
{
    foo[i] = i;
}

or:

int foo1;
int foo2;
int *p[] = { &foo1, &foo2 };   /* Array of pointers */
for (int i = 0; i < 2; i++)
{
    *p[i] = i;   /* Changes foo1 or foo2 */
}

I don't fully understand your last question, but if you mean that you want the data types to be Object * rather than int, then all you need to do is substitute Object * for int into my code examples above (other than for int i = 0, obviously).

Oli Charlesworth