Re: Dynamic variable names
- From: Joseph M. Newcomer <newcomer@xxxxxxxxxxxx>
- Date: Tue, 31 May 2005 23:18:46 -0400
I would suggest reconsidering the structure of your program. It is an interesting
observation that when you have structures like this, it is often because you are trying to
program C++ as if it were C, and the creation of abstract superclasses and specific
subclasses often eliminates the need for code like this.
joe
On Tue, 31 May 2005 15:50:10 -0700, "Macca" <Macca@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote:
>Hi,
>
>I have 16 structure variables that are very similar xxx1xxxx
>
>xxx2xxxx
>
>xxx3xxxx etc.
>
>Each structire variable has about 10 fields, i.e a lot!!!!
>
>instead of having to write out the variables in a switch statement when
>assigning and reading from them... e.g
>
>switch (NumVar)
>{
> case 1:
> xxx1xxx->field1 = ...
> xxx1xxx->field2 = ...
> xxx1xxx->field3 = ...
> .
> .
>
> case 2:
> xxx2xxx->field1 = ...
> xxx2xxx->field2 = ...
> xxx2xxx->field3 = ...
>
>
> etc
>
>What i would like to do is build up the variable name during run time to
>stop me having to repeat a lot of code.
>
>e.g
>xxxNumVarxxx->field1 = ...
>xxxNumVarxxx->field2 = ....
>
>and would mean i dont have to write out every case for every number i need.
>
>Can anyone tell me if this sort of thing is possible?
>
>Thanks
>Macca
Joseph M. Newcomer [MVP]
email: newcomer@xxxxxxxxxxxx
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
.
- References:
- Dynamic variable names
- From: Macca
- Dynamic variable names
- Prev by Date: Re: Item Image
- Next by Date: Re: VC++6 About Box Cancel Button
- Previous by thread: Re: Dynamic variable names
- Next by thread: Undeclaired Identifier
- Index(es):