Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c++ > #9487
| From | "Gernot Frisch" <me@privacy.net> |
|---|---|
| Newsgroups | comp.lang.c++ |
| Subject | access members by string name |
| Date | 2011-08-30 16:53 +0200 |
| Message-ID | <9c4brfFfu2U1@mid.individual.net> (permalink) |
Hi,
assume you have a class with members (or member get/set functions) and want
to call them by a string name with the least code to maintain.
I like to just have one macro line per member. The class should have a
working assignment operator.
The end class should look like:
class foo
{
int bar;
int goo;
public:
...
int GetGoo()const {return goo;}
void SetGoo(int g) {goo = g;}
...
std::map<std::string, something_to_map_the_GET_function> getfunctions;
static std::string GetAllParams() {return std::string("bar,goo");}
int GetVar(std::string name) {return getfunctions[name] () ; }
};
Back to comp.lang.c++ | Previous | Next — Next in thread | Find similar | Unroll thread
access members by string name "Gernot Frisch" <me@privacy.net> - 2011-08-30 16:53 +0200
Re: access members by string name Paavo Helde <myfirstname@osa.pri.ee> - 2011-08-30 10:26 -0500
Re: access members by string name "Gernot Frisch" <me@privacy.net> - 2011-08-31 11:58 +0200
Re: access members by string name Michael DOUBEZ <michael.doubez@free.fr> - 2011-08-31 04:08 -0700
csiph-web