Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!news.musoftware.de!wum.musoftware.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: "Gernot Frisch" Newsgroups: comp.lang.c++ Subject: access members by string name Date: Tue, 30 Aug 2011 16:53:35 +0200 Lines: 28 Message-ID: <9c4brfFfu2U1@mid.individual.net> Mime-Version: 1.0 Content-Type: text/plain; format=flowed; charset="iso-8859-1"; reply-type=original Content-Transfer-Encoding: 7bit X-Trace: individual.net DZyr6PcJsK4ilsIGfb2Wbg35ymGXLI4vblqcdv0qpOTsfke+I= Cancel-Lock: sha1:bDeFafEmSH3MN6zbthLeOnIJ/LI= X-Priority: 3 X-MSMail-Priority: Normal Importance: Normal X-Newsreader: Microsoft Windows Live Mail 15.4.3538.513 X-MimeOLE: Produced By Microsoft MimeOLE V15.4.3538.513 Xref: x330-a1.tempe.blueboxinc.net comp.lang.c++:9487 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 getfunctions; static std::string GetAllParams() {return std::string("bar,goo");} int GetVar(std::string name) {return getfunctions[name] () ; } };