Array of struct: access them by name?

Not sure if this is possible, but I am trying to make a data structure that contains all the elements I need, so I can loop through them and initialize them.

So instead of have

struct MYSTRUCT item1, item2, ...itemN;

...
item1.attr1 = "x";
item1.attr2 = 2;
....
item2.attr1 = "y";
item2.attr2 = 1;
...

I can use something like

struct MYSTRUCT allstructs[] = {item1, item2, ...itemN};
int item_number = 5;

for (i = 0; i< item_number; i++)
{
allstructs*.attr2 = i;*
}[/quote]
So I have to set only a limited amount of properties for each entry in the array.
Although I may not know which item is at position 1, 2 or whatever other position in the array, so my question is: can I use the name of the variable (item1, item2 and so on), instead of the position in the array?
So I can do something like
> allstructs[item1].attr1 = "x";

Thanks for the reply.

I get your point, and the enum option is feasible. I have to try the implementation.

The reason for giving names? It exist even if you use an array. Consider the case where you have a struct that identify a type of element, like a dog. You want to have a cluster of dogs, so you can parse them all and see for example, who has a microchip.

If I have an array of dogs; I can read or write on their microchip in sequence, because they have common properties, but they have also different properties (their name, their breed, their size); some of which are unique, while other are relevant only to a subset of them.

Of course there are other ways to do this; I was just pointing out why it make sense for me to go in that route; I am not stating that this is the only way. I do use other languages; and sometimes you get used to what you do in a different language, and subconsciously do the same for all the other languages.

You should be able to do this with a (dog)class with static methods to keep track of the number of objects(dogs) and perform the bulk initializations.

have you considered using a container class such as the STL map?
http://www.cplusplus.com/reference/map/map/

there is an implementation of the STL for the Arduino