Class Variable Question

Robert Johnson rjohnson at exotic-eo.com
Wed Apr 11 04:14:01 EDT 2001


> Consider an *instance* of a std::map< std::string, std::string >, for
> example.  You CAN "just add things on the fly" to it, can't you?  Isn't
> it handy, indeed sometimes crucial, to be able to add any foo->bar
> mapping entry to the class on the fly, as and if and when the need
> arises, at runtime, rather than having to pre-declare all the set
> of 'keys' that are going to be allowed and/or mandatory for all
> instances of such a type...?

I am not sure you understand the point I am trying to make here.  Even if I
were to make a map with void* where the type of the object being stored
becomes irrelevant, it still would not be what I am talking about.  The only
way to add anything to your mapInstance is to add strings like:

mapInstance["Python"]="Is cool, please don't shoot me."

I can't simply expand the object by adding new variables that have nothing
to do with the laid-out definition of the map.  Once I instantiate the map,
I can't simply type "mapInstance.newVariable=5".





More information about the Python-list mailing list