Re: great c++ question
On Jun 21, 10:20 am, "Gernot Frisch" <M...@Privacy.net> wrote:
You can't do that with Standard C++. However, I think you
might be able to use a modified C++ compiler that has some
reflection techniques wrt storing a full-blown metadata
representation of the class in the compiled binary. The
metadata could store the data-members along with their types
and names.
Why would you? You can use boost::any vectors for that. No need for a
special tool.
As John has pointed out, a map of boost::any just adds values to
an object---a single instance of a class. Presumably, by adding
something like a static:
static std::map< std::string, std::type_info const* >
ourMembers ;
and adding whatever checks are appropriate to the getters and
setters of the class, you could get the same effect as adding
members dynamically to a class. The same effect, but no where
near the same syntax. Where as with a compiler modification,
you could write something like:
std::string name ;
std::cin >> name ;
std::cout << container.name ...
Of course, even with the compiler modifications, you couldn't
get the static typechecking which otherwise characterizes C++
class members.
--
James Kanze (GABI Software, from CAI) email:james.kanze@gmail.com
Conseils en informatique orient=E9e objet/
Beratung in objektorientierter Datenverarbeitung
9 place S=E9mard, 78210 St.-Cyr-l'=C9cole, France, +33 (0)1 30 23 00 34