Re: Iterate through member variables of a class
From: David Hilsee (davidhilseenews_at_yahoo.com)
Date: 08/05/04
- Next message: Phlip: "Re: [Snippet] a Recursive Descent Parser via TDD - recursiveDescentParser.h"
- Previous message: Ioannis Vranos: "Re: Feeling kind of stupid about pointers"
- In reply to: Stephen Tyndall: "Re: Iterate through member variables of a class"
- Next in thread: Siemel Naran: "Re: Iterate through member variables of a class"
- Reply: Siemel Naran: "Re: Iterate through member variables of a class"
- Reply: Stephen Tyndall: "Re: Iterate through member variables of a class"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Wed, 4 Aug 2004 23:11:42 -0400
"Stephen Tyndall" <swtyndall@hotmail.com> wrote in message
news:Hv-dnTPdNuLCPozcRVn-vQ@comcast.com...
> "bst" <bstom@import.com> wrote in message
> news:9WfQc.387998$Gx4.257975@bgtnsc04-news.ops.worldnet.att.net...
> > Is there a way to iterate through member variables of different names,
of
> > course, one by one from the very first one in a while loop, for example?
> > Thanks!
>
> I'm probably doing something stupid, but did you mean something like this?
> Even if something's wrong with it (and there probably is), at least I'll
> learn something when everyone corrects me :)
>
> One thing I do know that's wrong is the public member variables in both
> classes, but I left those in so that I could fool around with it (and I
> can't think of any other way to make this setup work).
[snip]
> class Reader {
>
> public:
>
> Reader(ReadMe& readFromThis) : target(readFromThis) { }
>
> void printTargetVars() const;
>
> ReadMe& target;
>
> };
>
> void Reader::printTargetVars() const {
>
> int* arr[4] = { &target.var1, &target.var2, &target.var3, &target.var4 };
>
> int i = 0;
>
> while(i < 4) {
>
> cout << *arr[i] << "\n";
>
> ++i;
>
> }
[snip]
Looks OK to me, except for the public members and a few minor tweaks that
could be made. Another option is to forego individual members and just use
an array from the start.
-- David Hilsee
- Next message: Phlip: "Re: [Snippet] a Recursive Descent Parser via TDD - recursiveDescentParser.h"
- Previous message: Ioannis Vranos: "Re: Feeling kind of stupid about pointers"
- In reply to: Stephen Tyndall: "Re: Iterate through member variables of a class"
- Next in thread: Siemel Naran: "Re: Iterate through member variables of a class"
- Reply: Siemel Naran: "Re: Iterate through member variables of a class"
- Reply: Stephen Tyndall: "Re: Iterate through member variables of a class"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|