translating "setattr" to C++

Peter Hansen peter at engcorp.com
Fri Mar 19 08:27:00 EST 2004


Eric wrote:

> Slightly off topic, i know, but here goes:
> 
> I'm trying to xlate a module of mine to C++. Only problem is, it makes
> heavy use of "setattr". Anyone know a straightforward way to do
> "setattr" in C++ ?

Thinking about what setattr() does, and about how C++ works, I suspect
there is no straightforward way.  There _might_ be some existing library 
for introspection that can do something resembling what you want.

Think about it: setattr() uses the names of arbitrary (possibly 
non-existing, but of course you can't solve that in C++ at all) 
attributes that are contained in strings.  That means the resolution is 
done at run-time.  In C++, on the other hand, all the names pretty much 
vanish at compile-time, so unless you prepare mappings of some kind 
ahead of time, or have a package which can read dynamically from header 
files or something, you're plain screwed.  AFAICS.

-Peter



More information about the Python-list mailing list